2

I have a csv file with the following headers - Interaction_ID, PDB_ID, First_Residue, First_Chain, Second_Residue, Third_Residue, Third_Chain & Pattern:

AM_AUTO_1,1cx0,A166,B,C118,B,G129,B,A-minor Type I ACG                            
AM_AUTO_2,1cx0,A165,B,C119,B,G128,B,A-minor Type II ACG                           
AM_AUTO_3,1cx0,A166,B,C119,B,G128,B,A-minor Type II ACG                           
AM_AUTO_4,1ddy,A25,A,C21,A,G8,A,A-minor Type I ACG                            
AM_AUTO_5,1e7k,A33,C,C28,C,G45,C,A-minor Type 0 AGC                            
AM_AUTO_6,1e7k,A33,D,C28,D,G45,D,A-minor Type 0 AAU

What I would like to do is delete rows in the csv file where Pattern = %Type 0% and then print the resulting csv file. The result should be like this:

AM_AUTO_1,1cx0,A166,B,C118,B,G129,B,A-minor Type I ACG                            
AM_AUTO_2,1cx0,A165,B,C119,B,G128,B,A-minor Type II ACG                           
AM_AUTO_3,1cx0,A166,B,C119,B,G128,B,A-minor Type II ACG                           
AM_AUTO_4,1ddy,A25,A,C21,A,G8,A,A-minor Type I ACG  

How I can do this using awk?

1

With awk, you can do:

$ awk '$(NF-1)!=0' file
AM_AUTO_1,1cx0,A166,B,C118,B,G129,B,A-minor Type I ACG
AM_AUTO_2,1cx0,A165,B,C119,B,G128,B,A-minor Type II ACG
AM_AUTO_3,1cx0,A166,B,C119,B,G128,B,A-minor Type II ACG
AM_AUTO_4,1ddy,A25,A,C21,A,G8,A,A-minor Type I ACG

or using grep:

grep -v 'Type 0' file
1

Using awk:

awk -F, '$9!~/Type 0/{print $0}' file
AM_AUTO_1,1cx0,A166,B,C118,B,G129,B,A-minor Type I ACG
AM_AUTO_2,1cx0,A165,B,C119,B,G128,B,A-minor Type II ACG
AM_AUTO_3,1cx0,A166,B,C119,B,G128,B,A-minor Type II ACG
AM_AUTO_4,1ddy,A25,A,C21,A,G8,A,A-minor Type I ACG

Explanation:

This causes awk to use , as delimiter (-F,). If the 9th field doesn't contain "Type 0" ($9!~/Type 0/), print the line ({print $0}).

And a sed solution:

sed '/,[^,]*Type 0[^,]*$/d' file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.