The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




Thread: Delete help
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 10-12-2008
uwork72 uwork72 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 32
Delete help

Please give me some hints with awk or something, to delete the lines corresponding to a fixed 2nd field, for which A line is absent.

$ cat file.txt #Test file a 1 2232 ert a 1 679 asd A 1 12 oio a 2 131 sd a 2 56 adsad a 2 567 sassa A 2 90 asd a 4 234 gfg a 4 566 erer a 5 233 yu A 5 232 yuyu
Code:
$ cat file.txt
#Test file

a 1 2232 ert
a 1 679 asd
A 1 12 oio

a 2 131 sd
a 2 56 adsad
a 2 567 sassa
A 2 90 asd

a 4 234 gfg
a 4 566 erer


a 5 233 yu
A 5 232 yuyu
        
-->
Code:
$ cat file.txt
#Test file

a 1 2232 ert
a 1 679 asd
A 1 12 oio

a 2 131 sd
a 2 56 adsad
a 2 567 sassa
A 2 90 asd

a 4 234 gfg
a 4 566 erer


a 5 233 yu
A 5 232 yuyu
So the required output is something like this for the above file:

#Test file a 1 2232 ert a 1 679 asd A 1 12 oio a 2 131 sd a 2 56 adsad a 2 567 sassa A 2 90 asd a 5 233 yu A 5 232 yuyu
Code:
#Test file

a 1 2232 ert
a 1 679 asd
A 1 12 oio

a 2 131 sd
a 2 56 adsad
a 2 567 sassa
A 2 90 asd

a 5 233 yu
A 5 232 yuyu
        
-->
Code:
#Test file

a 1 2232 ert
a 1 679 asd
A 1 12 oio

a 2 131 sd
a 2 56 adsad
a 2 567 sassa
A 2 90 asd

a 5 233 yu
A 5 232 yuyu
Thank you.