shell实现从gff文件的第9列提取基因名称
001、sed
[root@PC1 test]# ls a.txt [root@PC1 test]# cat a.txt ## 测试数据 ID=gene-LOC124418406;Dbxref=GeneID:124418406;Name=LOC124418406;gbkey=Gene;gene=LOC124418406;gene_biotype=lncRNA ID=gene-LOC121106832;Dbxref=CGNC:86713,GeneID:121106832;Name=LOC121106832;gbkey=Gene;gene=LOC121106832;gene_biotype=lncRNA ID=gene-LOC107049418;Dbxref=CGNC:72437,GeneID:107049418;Name=LOC107049418;gbkey=Gene;gene=LOC107049418;gene_biotype=lncRNA ID=gene-LOC124417607;Dbxref=GeneID:124417607;Name=LOC124417607;gbkey=Gene;gene=LOC124417607;gene_biotype=lncRNA ID=gene-RNF212B;Dbxref=CGNC:55930,GeneID:770305;Name=RNF212B;gbkey=Gene;gene=RNF212B;gene_biotype=lncRNA [root@PC1 test]# sed 's/\(^.*\+\)\(gene=\S\+\)\(;.*\)/\2/' a.txt ## 提取命令 gene=LOC124418406 gene=LOC121106832 gene=LOC107049418 gene=LOC124417607 gene=RNF212B
002、awk
[root@PC1 test2]# ls a.txt [root@PC1 test2]# cat a.txt ID=gene-LOC124418406;Dbxref=GeneID:124418406;Name=LOC124418406;gbkey=Gene;gene=LOC124418406;gene_biotype=lncRNA ID=gene-LOC121106832;Dbxref=CGNC:86713,GeneID:121106832;Name=LOC121106832;gbkey=Gene;gene=LOC121106832;gene_biotype=lncRNA ID=gene-LOC107049418;Dbxref=CGNC:72437,GeneID:107049418;Name=LOC107049418;gbkey=Gene;gene=LOC107049418;gene_biotype=lncRNA ID=gene-LOC124417607;Dbxref=GeneID:124417607;Name=LOC124417607;gbkey=Gene;gene=LOC124417607;gene_biotype=lncRNA ID=gene-RNF212B;Dbxref=CGNC:55930,GeneID:770305;Name=RNF212B;gbkey=Gene;gene=RNF212B;gene_biotype=lncRNA [root@PC1 test2]# awk -F "gene=" '{print $2}' a.txt | cut -d ";" -f 1 LOC124418406 LOC121106832 LOC107049418 LOC124417607 RNF212B