如何在两列和超过两个条件下使用awk [英] how to use awk for two columns and more than 2 conditions
本文介绍了如何在两列和超过两个条件下使用awk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用awk从我的数据中提取一些信息.
I would like to use awk to extract some information from my data.
作为一个例子,我有一个5列的数据 我想基于col1和col2提取 提取col1为'a'且col2以'LINE'或'SINE'或'ERV'开头的所有行
As an example I have a data with 5 column I would like to extract based on col1 and col2 Extract all lines where col1 is 'a' and col2 starts with 'LINE' or 'SINE' or 'ERV'
我尝试过
awk '{if ($1 == "a" && $2 ~ /SINE/ || $2 ~ /LINE/ || $2 ~ /ERV/ ) print $0}' myData.txt
这不起作用
推荐答案
您可以使用:
awk '$1 == "a" && $2 ~ /^(LINE|SINE|ERV)/' myData.txt
这篇关于如何在两列和超过两个条件下使用awk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文