- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- grep command
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2005 08:33 AM
01-27-2005 08:33 AM
grep command
I am trying to grep a word "connect" in files but grep command will return the entire line that contain the word "connect" in.
For example:
file text.txt has the following line:
"Uncomment the next line for more connect information */"
Command:
$ grep connect text.txt
Will return the entire line.
I would like to get just "more connect information" not the entire line or subset of the line but still contain the word "connect".
Is there a way to do this in shell script?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2005 09:05 AM
01-27-2005 09:05 AM
Re: grep command
Are you trying to change the word or import it to another file or script?
Maybe you can offer a bit more explanation...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2005 09:14 AM
01-27-2005 09:14 AM
Re: grep command
What I am trying to do is that instead of display the entire line from the grep output result, I would like to display subset of the return line.
If "grep connect text.file" will return output:
"your connection to database abc failed"
I would like to display just the "connection to database".
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2005 09:24 AM
01-27-2005 09:24 AM
Re: grep command
awk '
/^connect/ {
if ( NF == 1 ) print $i;
else print $i, $(i+1);
next;
}
/connect$/ {
print $(i-1), $i;
next;
}
/connect/ {
for ( i=1;i<=NF;i++) {
if ( $i ~ "connect" ) {break;}
}
print $(i-1), $i, $(i+1);
}' yourfile
this will print the word before and after "connect".
and i'm sure using perl's patteren matching capabilities would work much better.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2005 09:27 AM
01-27-2005 09:27 AM
Re: grep command
awk '
/^connect/ {
if ( NF == 1 ) print $1;
else print $1, $2;
next;
}
/connect$/ {
print $(NF-1), $NF;
next;
}
/connect/ {
for ( i=2;i
}
print $(i-1), $i, $(i+1);
}' yourfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2005 09:28 AM
01-27-2005 09:28 AM
Re: grep command
I'm not sure, that you can do what you want with grep only. If you know sructure of strings in the file, you can do either:
grep connect text.txt | awk '{print $3,$4,$5}' or
grep connect text.txt |cut -c10-25
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2005 10:08 AM
01-27-2005 10:08 AM
Re: grep command
perl -n -e 'print "$1 $2 $3\n" if /(\*S+)\s+(connect)\s+(\S*)/i' text.txt
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2005 06:44 PM
01-27-2005 06:44 PM
Re: grep command
I am ussuming you just want matches for the word connect and not words that is like reconnect or connection.
grep " connect " file.txt
That should do the trick
Hope this is what you want
Gerhard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2005 10:02 AM
01-28-2005 10:02 AM