Linux Command テキスト処理

http://cmdnote.net/search?q=tag%3Alinux_command に移転します。

ファイルのある行番号の範囲を標示する

ファイルを先頭から 10 行、末尾から 10 行表示するには次のようにする。

head -n 10 file.txt
tail -n 10 file.txt

11 行目以降、後ろから 11 行目まで表示するには次のようにする。

tail -n +10 file.txt
head -n -10 file.txt

10 行目から 20 行目まで表示するには次のようにする。

sed -n "10,20p" file.txt

10行おきに表示する

sed -n -e "1~10p" file.txt

ファイルの文字コードをまとめて変換する

find と nkf の「–overwrite」オプションを使えばよい。 たとえば、UTF8 に変換するには

find /path/to/dir -type f | xargs -n 1 nkf -w --overwrite

のようにする。

Tags of current page

,