最後の列を除き、スペースをTABに置き換えます。

最後の列を除き、スペースをTABに置き換えます。

次のファイルがあります。 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

関連情報