简体   繁体   English

awk在列中打印特定数量的字符

[英]awk print specific number of character in columns

I have a file with many columns and rows and I want to remove the rows that are more than one character in the fourth and fifth columns. 我有一个包含许多列和行的文件,并且我想删除第四列和第五列中超过一个字符的行。

Input: 输入:

--- 22:16050115:G:A 16050115 GGG A
--- 22:16050213:C:T 16050213 C T
--- 22:16050319:C:T 16050319 C T
--- 22:16050527:C:A 16050527 C AAA
--- 22:16050568:C:A 16050568 CC A
--- 22:16050607:G:A 16050607 G A
--- 22:16050627:G:T 16050627 G TGG
--- 22:16050646:G:T 16050646 G T
--- 22:16050655:G:A 16050655 GTAA A
...

Desired output: 所需的输出:

--- 22:16050213:C:T 16050213 C T
--- 22:16050319:C:T 16050319 C T
--- 22:16050607:G:A 16050607 G A
--- 22:16050646:G:T 16050646 G T
...

Thank you very much. 非常感谢你。

awk 'length($4)==1 && length($5)==1' inputfile
--- 22:16050213:C:T 16050213 C T
--- 22:16050319:C:T 16050319 C T
--- 22:16050607:G:A 16050607 G A
--- 22:16050646:G:T 16050646 G T

This will check the length of $4 and $5 using length() function of awk . 这将使用awk length()函数检查$4$5 length() This is using comparison operator == . 这是使用比较运算符== You can modify it to < , > , <= etc. So the above command will print the lines which have only one character in their 4th and 5th column. 您可以将其修改为<><=等。因此,以上命令将在第4列和第5列中打印只有一个字符的行。

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

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