捕获字符串忽略转义序列
我的输入文件具有以下条目:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需查找字段大于 3 个
概念验证的行
Just look for lines that have fields greater than 3
Proof of Concept
你也可以尝试
you can also try