How to print lines based on values in multiple columns

喜你入骨 提交于 2019-12-13 05:09:53

问题


I'd like to print every line in my file that satisfies the following:

print line if column 3 or column 4 or column 5 is less than 10

Example

Emma   A  10  4  7
Sally  A  4   4  7
Jack   B  15  19 2
Jeff   C  15  20 25
Mary   A  15  20 25
Meg    C  2   7  9

Output

Emma   A  10  4  7
Sally  A  4   4  7
Jack   B  15  19 2 
Meg    C  2   7  9

回答1:


It's pretty simple with awk:

awk '$3<10 || $4<10 || $5<10' file

The output:

Emma A 10 4 7
Sally A 4 4 7
Jack B 15 19 2
Meg C 2 7 9


来源:https://stackoverflow.com/questions/47927892/how-to-print-lines-based-on-values-in-multiple-columns

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!