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!

Need Help ASAP With Nawk

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
US
I have a file which has lines in it like:

B00563A
YES 7
B00507C
NO 7
B00507B
YES 7
B00507A
NO 7
B00216C
YES 7
B00216B
NO 7

I am on Solaris 8 so I have been using nawk and it has worked quite well.

I need to send to a new file called beaster1 the following items. If the above lines have a YES in it, send only the line above it to the new file beaster1. So the output would be similiar to the below example.

B00563A
B00507B
B00216C

Thanks for the help! I need this pretty rapidly, sorry for the rush, BeasteR
 

Hi beaster!

Please, try this awk query:

Code:
awk "NF == 1 { id = $0 }  NF == 2 && /YES/ { print id }" inputfile

Bye!

KP.
 

Oops!

I use awk for DOS/Win. So, previous awk program must be enclosed between single quotes.

Bye!

KP.
 
Thanks fot the help! I'm sorry what do you mean?

.//beaster
 

$1 !~ /(YES|NO)/ { thingy = $1 }
$1 ~ /YES/ { print thingy }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top