捕获字符串忽略转义序列

发布于 2024-10-21 02:37:43 字数 634 浏览 0 评论 0原文

我的输入文件具有以下条目:

0100000000010001000   1       GWSL7YE02GHT73, 
0010000000000000000   1       GWSL7YE02GU6GK, 
0000000000000000000   1       GWSL7YE02G5W2B, 
0010000000110000000   1       GWSL7YE02I364F, 
0000000000000000000   1       GWSL7YE02F4IOC, Escherichia_coli_O127:H6

如何仅捕获末尾有字符串的行,例如第 5 行。 另外需要注意的是,每一行都有两个转义序列“\t”“\n”。 因此,在第 1-5 行中,不要认为“,”之后有转义字符“\n”,但实际上它是“\t”“\n”。 我确实有以下 awk 代码:awk '{if ($0~/[A-Z0-9_]$/) print$NF}',但是,这假设有字母表、数字末尾取消划线。实际上,名称可以以任何特殊字符结尾。我已经测试过,因此我必须加下划线“_”。那么除了这个还有没有别的办法呢。我可以有 awk '{if ($NF!~/an expression that matches ,\n\t/}'

谢谢

My input file has following entries:

0100000000010001000   1       GWSL7YE02GHT73, 
0010000000000000000   1       GWSL7YE02GU6GK, 
0000000000000000000   1       GWSL7YE02G5W2B, 
0010000000110000000   1       GWSL7YE02I364F, 
0000000000000000000   1       GWSL7YE02F4IOC, Escherichia_coli_O127:H6

How can I only capture line that have string at the end, such as line 5.
Another thing to note is that in each line at the there are two escape sequences "\t" "\n".
So in lines 1-5 do not think that after"," there is escape char "\n", BUT in reality it is ,"\t""\n".
I did had have following awk code:awk '{if ($0~/[A-Z0-9_]$/) print$NF}', However, this assumes that there are either alphabets,number of undescore at the end. In reality the names can end with any special characters.I have tested hence I had to put an underscore"_". So is there a way other then this. Can I have something as awk '{if ($NF!~/an expression that maps ,\n\t/}'

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

假装不在乎 2024-10-28 02:37:43

只需查找字段大于 3 个

awk 'NF>3' ./infile

概念验证的行

$ cat -A lastfield
0100000000010001000   1       GWSL7YE02GHT73,^I$
0010000000000000000   1       GWSL7YE02GU6GK,^I$
0000000000000000000   1       GWSL7YE02G5W2B,^I$
0010000000110000000   1       GWSL7YE02I364F,^I$
0000000000000000000   1       GWSL7YE02F4IOC,^IEscherichia_coli_O127:H6^I$

$ awk 'NF>3' lastfield
0000000000000000000   1       GWSL7YE02F4IOC,   Escherichia_coli_O127:H6

Just look for lines that have fields greater than 3

awk 'NF>3' ./infile

Proof of Concept

$ cat -A lastfield
0100000000010001000   1       GWSL7YE02GHT73,^I$
0010000000000000000   1       GWSL7YE02GU6GK,^I$
0000000000000000000   1       GWSL7YE02G5W2B,^I$
0010000000110000000   1       GWSL7YE02I364F,^I$
0000000000000000000   1       GWSL7YE02F4IOC,^IEscherichia_coli_O127:H6^I$

$ awk 'NF>3' lastfield
0000000000000000000   1       GWSL7YE02F4IOC,   Escherichia_coli_O127:H6
椒妓 2024-10-28 02:37:43

你也可以尝试

awk -F, 'NF>1' file

you can also try

awk -F, 'NF>1' file
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文