![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Cutting specific lines from a file | pathanjalireddy | Shell Programming and Scripting | 15 | 06-04-2009 02:32 AM |
| overwrite specific lines in a file | csecnarf | Shell Programming and Scripting | 7 | 05-13-2008 12:01 PM |
| how to remove specific lines from a file | bluemoon1 | Shell Programming and Scripting | 17 | 10-07-2007 11:40 PM |
| replacing specific lines in a file | hcclnoodles | Shell Programming and Scripting | 6 | 09-30-2006 12:35 PM |
| How do you specific lines in a file? | hedgehog001 | UNIX for Dummies Questions & Answers | 2 | 08-23-2005 01:04 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
retrieving specific lines from a file - can I use grep ?
Hi there, if i had a file that looked like this Code:
my_server1 red green blue yellow blue my_server2 blue blue yellow green blue my_server3 yellow yellow blue and I wanted to be able to grep for the hostname line and every instance of , say the word blue that appear below that hostname (but above the next hostname) ...what tool could i use ...it seems to me that grep doesnt seem to have the ability to be as specific as I require ...is there anything else ? I want to get an output like this Code:
my_server1 blue blue my_server2 blue blue blue my_server3 blue any help on this would be great |
|
||||
|
thanks for the reply, it didnt work so i removed the last bit, the awk statement (see below) and even the grep on its own is not returning anything Code:
cat file | grep 'blue' my_server* to be honest im a bit lost with this one |
|
||||
|
Thankyou very much for taking the effort to give me those three options..I have tried them all with no success though ... I thank you anyway Code:
# grep -e my_server -e blue /opt/my_file grep: illegal option -- e Usage: grep -hblcnsviw pattern file . . . # awk '$0 ~ "my_server|blue"' /opt/my_file awk: syntax error near line 1 awk: bailing out near line 1 # sed '/my_server\|blue/p;d' /opt/my_file # <<< no output |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|