[英]BASH - Delete specific lines
I need to remove every line that has value like SUPMA
in the 4th column. 我需要在第4列中删除每个具有SUPMA
值的行。
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. 在这个例子中,我想保留第3行和第5行。
How can i do this in bash script? 我怎样才能在bash脚本中执行此操作? Can i use AWK? 我可以使用AWK吗?
Thanks 谢谢
awk -F";" '$4!="SUPMA"' yourfile.txt
Here awk splits the records by semicolon, then tests the 4th position for SUPMA
. 这里awk用分号分割记录,然后测试SUPMA
的第4个位置。 By default, if that condition passes, it will print the line. 默认情况下,如果该条件通过,它将打印该行。
awk -F\; '$4 !~/SUPMA/' file
SUPMA;def;ghi;MA;klm
abc;def;ghi;SUP;klm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.