简体   繁体   English

使用awk过滤文本文件中的行

[英]Filtering rows in a text file using awk

I have tab delimited text file (like this): 我有制表符分隔的文本文件(像这样):

A  1 A1g DELL
A  1 B1s HP
A  7 Zfd Nog
A  5 Jgf KIT
A  1 Def JOP

Apart from the first row, I would like to keep only the rows where the second column's value is larger than 1. 除了第一行,我只想保留第二列的值大于1的行。

A  1 A1g DELL
A  7 Zfd Nog
A  5 Jgf KIT

I tried awk '{if($2>1) print }' file.txt but it omits the first row. 我尝试了awk '{if($2>1) print }' file.txt但是省略了第一行。 How can I skip the first row and check the condition ($2 >1) for other rows? 如何跳过第一行并检查其他行的条件($2 >1)

Thanks in advance. 提前致谢。

In AWK: 在AWK中:

$ awk 'NR==1||$2>1' test.in
A  1 A1g DELL
A  7 Zfd Nog
A  5 Jgf KIT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM