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

find and print fields between 1

Status
Not open for further replies.

enni

Technical User
Oct 30, 2003
5
EE
Hi

I've a input file output looks like this;

Record
"bbbb" = "llll"
"aaaa" = "98874"
"cccc" = "ccccc"
"dddd" = "eeeee"
End Record
Record
"bbbb" = "llll"
"aaaa" = "98874"
"cccc" = "ddddd"
"dddd" = "ffff"
End
Record
"bbbb" = "llll"
"aaaa" = "98984"
"cccc" = "ddddd"
"dddd" = "ffff"
End

I need to print out all lines between Record and End Record if "aaaa" field is "98984"

Any help would be greatly appreciated.
 
This is untested, but might get you started

/^Record/{flg=1;a[++ix]=$0}
flg{a[++ix]=$0;if ($1="\"aaaa\"" && $2!="\"98984\"") flg=0}
/^End/ && flg{for (j=1;j<=ix;j++) print a[j]; print; flg=0}


CaKiwi

&quot;I love mankind, it's people I can't stand&quot; - Linus Van Pelt
 
Try something like this:
Code:
awk '
/^Record/{ok=0;t=0;next}
/^&quot;aaaa&quot; = &quot;98984&quot;/{ok=1}
/^End/{if(ok)for(i=1;i<=t;++i)print a[i];next}
{a[++t]=$0}
' /path/to/input >/path/to/output

Hope This Help
PH.
 
Thanx Phv
this help me lot. At the moment both Records and End lines will be removed, but i need to know also Records line values, so can you help me out also ???

 
If you want to keep Record and End sources lines, just suppress the two 'next' at the end of the
Code:
/^Record/
and
Code:
/^End/
script lines and put the
Code:
/^End/
script line at the end (after the
Code:
{a[++t]=$0}
line).

&quot;When all else has failed, read the manuals.&quot;

Denis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top