첫 번째 열의 첫 번째 공백 뒤의 문자열만 제거

첫 번째 열의 첫 번째 공백 뒤의 문자열만 제거

다음 파일은 탭으로 구분됩니다. 나는 첫 번째 열에서 NbLab330C00 64506568공백 뒤의 숫자를 제거하여 NbLab330C00.

$ head LAB330_TE_annotation.gff3 
##gff-version 3      
##date Sun Feb 14 08:41:36 UTC 2021      
##Identity: Sequence identity (0-1) between the library sequence and the target region.      
##ltr_identity: Sequence identity (0-1) between the left and right LTR regions.      
##tsd: target site duplication.      
##seqid source sequence_ontology start end score strand phase attributes      
NbLab330C00 64506568    EDTA    Gypsy_LTR_retrotransposon   2   3364    20798   -   .   ID=TE_homo_0;Name=TE_00007365_INT;Classification=LTR/Gypsy;Sequence_ontology=SO:0002265;Identity=0.868;Method=homology      
NbLab330C00 64506568    EDTA    Gypsy_LTR_retrotransposon   3367    4198    3385    -   .   ID=TE_homo_1;Name=TE_00008087_LTR;Classification=LTR/Gypsy;Sequence_ontology=SO:0002265;Identity=0.865;Method=homology      
NbLab330C00 64506568    EDTA    hAT_TIR_transposon  4424    4715    1278    +   .   ID=TE_homo_2;Name=TE_00003964;Classification=DNA/DTA;Sequence_ontology=SO:0002279;Identity=0.834;Method=homology      
NbLab330C00 64506568    EDTA    hAT_TIR_transposon  5236    5453    835 +   .   ID=TE_homo_3;Name=TE_00001425;Classification=DNA/DTA;Sequence_ontology=SO:0002279;Identity=0.828;Method=homology 

다음 명령을 시도했지만 awk마지막 열도 단축되었습니다.

$ awk -v OFS='\t' '{print $1,$3,$4,$5,$7,$8,$9}' LAB330_TE_annotation.gff3 > LAB330_TE_annotation.fix.gff3
(base) ubuntu@ip-10-23-2-113:/efs/apollo/LAB330$ head LAB330_TE_annotation.fix.gff3 
##gff-version                       
##date  Feb 14  08:41:36    2021        
##Identity: identity    (0-1)   between library sequence    and
##ltr_identity: identity    (0-1)   between left    and right
##tsd:  site    duplication.                
##seqid sequence_ontology   start   end strand  phase   attributes
NbLab330C00 EDTA    Gypsy_LTR_retrotransposon   2   20798   -   .
NbLab330C00 EDTA    Gypsy_LTR_retrotransposon   3367    3385    -   .
NbLab330C00 EDTA    hAT_TIR_transposon  4424    1278    +   .
NbLab330C00 EDTA    hAT_TIR_transposon  5236    835 +   .
(base) ubuntu@ip-10-23-2-113:/efs/apollo/LAB330$ 

위의 명령을 수정하는 방법,

미리 감사드립니다.

ベストアンサー1

awk 'BEGIN{ OFS=FS="\t" } 
  !/^#/{ sub(/ [0-9]+$/, "", $1) }
  1
' LAB330_TE_annotation.gff3 > LAB330_TE_annotation.fix.gff3

이렇게 하면 헤더 행이 #수정되지 않은 상태로 시작되고 첫 번째 필드 끝에 있는 공백 문자와 그 뒤에 최소한 하나의 숫자가 빈 문자열로 대체됩니다.

おすすめ記事