Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep

Status
Not open for further replies.

malladisk

Programmer
Jun 14, 2001
69
0
0
US
Hi, I have a file as follows

ABC_value1
..
..
MY_LINE
....
....

ABC_value2
...
..
MY_LINE
....
...
ABC_value3
...
...
MY_LINE
....
and so on. I want to search this file and output wherever MY_LINE occurs, prefixed by the ABC_ value that goes ahead of MY_LINE. There might be an ABC_valuei that might not have MY_LINE so I need to be able to search this file for all occurances of MY_LINE for all values of ABC_value.
How do I grep in this file so that it prints out ABC_valuei and MY_LINE, so that I can see in the output whether or not MY_LINE is defined for ABC_some value.
Example output:
ABC_value1
MY_LINE
ABC_value2
MY_LINE
ABC_value3
ABC_value4
ABC_valu5
MY_LINE

The above shows that MY_LINE is defined for ABC_ value1, valu2 and value5 but not value3 and value4. MY_LINE is a fixed string and ABC_value is variable, but always starts with ABC_.
Thanks a lot!
Sashi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top