다음과 같은 파일이 있습니다. ID로 시작하는 마지막 열을 제외하고 모든 공백을 TAB으로 바꾸려면 어떻게 해야 합니까?
chr1 13513 14763 Medtr1g004950 . + JCVI gene . ID=Medtr1g004950;Note=hypothetical protein
chr1 15282 16532 Medtr1g004960 . + JCVI gene . ID=Medtr1g004960;Note=hypothetical protein
chr1 30972 32222 Medtr1g004980 . + JCVI gene . ID=Medtr1g004980;Note=hypothetical protein
답변1
선택은 당신의 것입니다:
$ sed 's/ /\t/g; s/\t/ /10' file
chr1 13513 14763 Medtr1g004950 . + JCVI gene . ID=Medtr1g004950;Note=hypothetical protein
chr1 15282 16532 Medtr1g004960 . + JCVI gene . ID=Medtr1g004960;Note=hypothetical protein
chr1 30972 32222 Medtr1g004980 . + JCVI gene . ID=Medtr1g004980;Note=hypothetical protein
$ sed 's/ /\t/g; s/\t\([^\t]*\)$/ \1/' file
chr1 13513 14763 Medtr1g004950 . + JCVI gene . ID=Medtr1g004950;Note=hypothetical protein
chr1 15282 16532 Medtr1g004960 . + JCVI gene . ID=Medtr1g004960;Note=hypothetical protein
chr1 30972 32222 Medtr1g004980 . + JCVI gene . ID=Medtr1g004980;Note=hypothetical protein
답변2
awk '{l=$NF;$NF="";gsub(" ","\t",$0);gsub(/[[:space:]]$/, "", $0);print $0,l}' filename
chr1 13513 14763 Medtr1g004950 . + JCVI gene . ID=Medtr1g004950;Note=hypothetical protein
chr1 15282 16532 Medtr1g004960 . + JCVI gene . ID=Medtr1g004960;Note=hypothetical protein
chr1 30972 32222 Medtr1g004980 . + JCVI gene . ID=Medtr1g004980;Note=hypothetical protein