expandコマンド(tabをスペースに変換する)
これブログ上じゃ差が判らないけど、
$ cat sample.txt 1 2 3
(数字がタブ区切りで書かれている)
というファイルに対して、expandコマンドを実行すると
$ expand sample.txt > sample2.txt $ cat sample2.txt 1 2 3 $ ll sample* -rw-rw-r-- 1 yasuhiro_kawai yasuhiro_kawai 19 Nov 28 14:55 sample2.txt -rw-rw-r-- 1 yasuhiro_kawai yasuhiro_kawai 7 Nov 28 14:51 sample.txt
と、半角スペース区切りに変換される。
なので、
$ expand sample.txt |tr -s [:space:] > sample3.txt $ cat sample3.txt 1 2 3
とすれば、タブを半角スペース1つに変換できる。
追記:
と思ったら、
$ expand -1 sample.txt 1 2 3
と、引数に1を渡すことでタブを1つのスペースに変更するか指定できるみたい。
と、思ったらこれも違って、引数に指定したn-1個のスペースに変換するみたい
$ expand -1 sample.txt 1 2 3 $ expand -2 sample.txt 1 2 3 $ expand -3 sample.txt 1 2 3 $ expand -4 sample.txt 1 2 3 $ cat samplex.txt 11 12 31 $ expand -1 samplex.txt 11 12 31 $ expand -2 samplex.txt 11 12 31 $ expand -3 samplex.txt 11 12 31 $ expand -4 samplex.txt 11 12 31
む……?
どうやらタブ幅を指定しているみたいだ。ということは正確には
$ expand -t 1 sample.txt $ expand --tabs=1 sample.txt
とするのが正しいらしい