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!

Simple Awk question

Status
Not open for further replies.

hokky

Technical User
Nov 9, 2006
170
AU
Hi Guys,

I think this is simple, but I need some one nail it for me.

I got the input data like this pattern
Code:
-File
...
...
-Value
...
...
-Error --> # this row is optional 
....

The data sometimes contain error sometimes not, I just want to grab the data under -Value,

Here's the code I've tried

Code:
script_that_produce_the_data_above |
awk '/^\-Value/{
      getline
      while ($0 !~ /^\-Error/) || ($0 != "") 
      {print;getline}         
}'

Above code doesn't work, Any idea how to nail it. The problem is how to stop when it gets the bottom of the line.

Thanks guys



 
At first glance (haven't tried it out):

If you're comparing

not-like
not-equals

then join them with AND (&&) not with OR (||)

your while loop will only end at end of file because any line in the file either doesn't contain "-Error" or isn't empty

Code:
while (($0 !~ /^\-Error/) && ($0 != ""))


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top