Julien
Julien

Reputation: 165

BASH - Delete specific lines

I need to remove every line that has value like SUPMA in the 4th column.

My data looks like this:

abc;def;ghi;SUPMA;klm
abc;def;ghi;SUPMA;klm
SUPMA;def;ghi;MA;klm
abc;def;ghi;SUPMA;klm
abc;def;ghi;SUP;klm

In this example, I want to keep the 3th and 5th lines.

How can i do this in bash script? Can i use AWK?

Thanks

Upvotes: 1

Views: 86

Answers (2)

JNevill
JNevill

Reputation: 50019

awk -F";" '$4!="SUPMA"' yourfile.txt

Here awk splits the records by semicolon, then tests the 4th position for SUPMA. By default, if that condition passes, it will print the line.

Upvotes: 2

Claes Wikner
Claes Wikner

Reputation: 1517

 awk -F\; '$4 !~/SUPMA/' file 
    SUPMA;def;ghi;MA;klm
    abc;def;ghi;SUP;klm

Upvotes: 1

Related Questions