![](/img/trans.png)
[英]Extract substring in Linux environemnt using Sed/awk/grep or any other tool
[英]Extract substring with sed/awk/grep from .gff file
我有一个包含多行的文件,如下所示:
NODE_1_length Prodigal:2.6 CDS 11 274 . + 0 ID=PROKKA_00001;inference=ab initio prediction:Prodigal:2.6;locus_tag=PROKKA_00001;product=hypothetical protein
我想提取ID = PROKKA_ [任何数字]和'product ='之后的所有内容,以获得如下输出:
ID=PROKKA_00001 product=hypothetical protein
我在使用sed方面不是很熟练,因此我尝试调整一些在这里和周围找到的解决方案,但没有成功。 如果解决方案分两个步骤(一个用于ID,一个用于产品),也可以,那么我可以将两个结果合并到一个文件中。
如果您能说明所用的正则表达式,将不胜感激。
到目前为止,我尝试将问题一分为二(从ID出发)并尝试:
grep -o 'ID=PROKKA_[0-9]{1,5}*'
sed 's/^ID=PROKKA[0-9]*;//g/
grep -Po 'ID="K[^"]*'
但当然他们都不起作用。 感谢您的帮助!
您可以使用grep -oE
:
grep -oE 'ID=PROKKA_[0-9]+|product=[^;:]+' file
ID=PROKKA_00001
product=hypothetical protein
如果要在同一行中显示结果,请使用grep + paste
:
grep -oE 'ID=PROKKA_[0-9]+|product=[^;:]+' file | paste -s
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.