![使用 awk 或 sed 在特定列中使用双引号](https://linux22.com/image/1552935/%E4%BD%BF%E7%94%A8%20awk%20%E6%88%96%20sed%20%E5%9C%A8%E7%89%B9%E5%AE%9A%E5%88%97%E4%B8%AD%E4%BD%BF%E7%94%A8%E5%8F%8C%E5%BC%95%E5%8F%B7.png)
我有这样的输入:
##gff-version 3
chr1 TAIR10 mRNA 3631 5899 . + . ID AT1G01010.1 ;geneID AT1G01010 ;gene_name AT1G01010
chr1 TAIR10 exon 3631 3913 . + . Parent AT1G01010.1
chr1 TAIR10 exon 3996 4276 . + . Parent AT1G01010.1
chr1 TAIR10 exon 4486 4605 . + . Parent AT1G01010.1
chr1 TAIR10 exon 4706 5095 . + . Parent AT1G01010.1
chr1 TAIR10 exon 5174 5326 . + . Parent AT1G01010.1
chr1 TAIR10 exon 5439 5899 . + . Parent AT1G01010.1
我希望 ID、geneID 和 gene_name 有双引号,像下一个输出一样:
##gff-version 3
chr1 TAIR10 mRNA 3631 5899 . + . ID "AT1G01010.1" ;geneID "AT1G01010" ;gene_name "AT1G01010"
chr1 TAIR10 exon 3631 3913 . + . Parent "AT1G01010.1"
chr1 TAIR10 exon 3996 4276 . + . Parent "AT1G01010.1"
chr1 TAIR10 exon 4486 4605 . + . Parent "AT1G01010.1"
chr1 TAIR10 exon 4706 5095 . + . Parent "AT1G01010.1"
chr1 TAIR10 exon 5174 5326 . + . Parent "AT1G01010.1"
chr1 TAIR10 exon 5439 5899 . + . Parent "AT1G01010.1"
我一直在测试
awk '{sub($10, "\"&\""); print}' file.gtf
感谢您阅读我的问题
答案1
快速而肮脏
sed -E 's#(ID|Parent|gene_name) ([0-9A-Za-z.]+)#\1 \"\2\"#g'