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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grab a line under particular word... 1

Status
Not open for further replies.

h3nd

Programmer
Jul 1, 2006
147
AU
Hi guys

This should be simple question but I can't get it work,
I wanna grab the lines content between this gap [ERROR IN and INSTRUMENT ... ]from a particular file :

Here's the part of the content file :
Code:
...
ERRORS IN:
------------------------------------
ABCD
AB

INSTRUMENT LOAD TOTALS PER FILE ARE:
------------------------------------
...

so, the output should be :
ABCD
AB

Thanks guys
 
Hi

Just a strange [tt]sed[/tt] solution. When find the "ERRORS IN", skip the next line, then output the lines until finds "INSTRUMENT".
Code:
sed -n '/^ERRORS IN/{n;n;:l;/^INSTRUMENT/b;p;n;bl}' /input/file
Tested with GNU [tt]sed[/tt]. Probably not work with Unix [tt]sed[/tt]s.

And its [tt]awk[/tt] equivalent, just as ugly as the [tt]sed[/tt] one.
Code:
awk '/ERRORS IN/{getline;getline;while($0!~/^INSTRUMENT/){print;getline}}' /input/file

Feherke.
 
Thx feherke,

but I couldnt understand that sed.

What about in awk ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top