
[gene=xyzI]
다음과 같은 항목이 여러 개 있는 경우 패턴만 제거하려면 어떻게 해야 합니까?
>lcl|NZ_CP018664.1_gene_628 [gene=mscL] [locus_tag=AUO97_RS03160] [location=complement(694895..695326)]
내 출력은 다음과 같습니다.
>lcl|NZ_CP018664.1_gene_628 [locus_tag=AUO97_RS03160] [location=complement(694895..695326)]
답변1
간단한 교체를 위해 -sed
충분할 것입니다:
sed -E 's/\[gene=[a-z]{3}[A-Z]\] *//' file
산출:
>lcl|NZ_CP018664.1_gene_628 [locus_tag=AUO97_RS03160] [location=complement(694895..695326)]
파일 수정"제자리에"- 추가된 -i
옵션:sed -i ....
답변2
그리고 GNU awk
:
$ echo '>lcl|NZ_CP018664.1_gene_628 [gene=mscL] [locus_tag=AUO97_RS03160] [location=complement(694895..695326)]' | awk '{$0=gensub(/\s*\S+/,"",2)}1'
>lcl|NZ_CP018664.1_gene_628 [locus_tag=AUO97_RS03160] [location=complement(694895..695326)]
이 작업은 다음을 통해 수행할 수도 있습니다 cut
.
$ echo '>lcl|NZ_CP018664.1_gene_628 [gene=mscL] [locus_tag=AUO97_RS03160] [location=complement(694895..695326)]' | cut -d' ' -f1,3-
>lcl|NZ_CP018664.1_gene_628 [locus_tag=AUO97_RS03160] [location=complement(694895..695326)]