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!

return line above pattern 1

Status
Not open for further replies.

caltman

Programmer
Mar 26, 2003
12
US
I have a file (test.log) that contains the string: TOTAL_MEMBERS in various places. I need to get a listing of the line that is always two lines above this string, but my version of grep apparently doesn't support the -C flag. Is there a way to get the information that I need?

Example of file data:
...
14:47:27.400: VALUE="10"
14:47:27.400: TYPE="STRING"
14:47:27.400: NAME="TOTAL_MEMBERS"
...
14:47:27.572: VALUE="23"
14:47:27.572: TYPE="STRING"
14:47:27.572: NAME="TOTAL_MEMBERS"
...


This should return:
14:47:27.400: VALUE="10"
14:47:27.572: VALUE="23"

Any help is appreciated.

Coley
 
Try something like this:
Code:
awk '
/TOTAL_MEMBERS/{print a[NR%2]}
{a[NR%2]=$0}
' test.log


Hope This Help
PH.
 
Thanks - figured it would be simple. There's your star.

Coley
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top