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!

Need Help ASAP With Script 1

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
 
#!/bin/ksh
Code:
sed 's/ 7/ \;/;' initial_file | awk ' BEGIN { RS = ";" } {
        if ($NF ~  /YES/)
                print $1
                }' > beaster1


I think this will work for you.
 
It worked perfect! Thanks! .//beaster
 
Why not try

sed -e 'N;/\nYES.*/ s///;t' -e 'd' initial_file > beaster1

or as a script

#! /usr/bin/sed -f
N
/\nYES.*/ s///
t
d
# END OF SCRIPT

Cheers,
ND
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top