awk
読み方
意味
サンプル
以下の環境でだれかのサンプルをいくつか真似して実行してみた。
$ ls -l
total 8
drwxr-xr-x 2 Administrator なし 0 Jan 29 05:21 perl/
-rw-r--r-- 1 Administrator なし 10 Jan 14 15:53 sample.txt
-rw-r--r-- 1 Administrator なし 10 Jan 30 00:41 sample2.txt
サンプル1
以下のコマンドを実行する。
$ ls -l | awk '{print $5,$9}'
その結果は
0 perl/
10 sample.txt
10 sample2.txt
サンプル2
以下のコマンドを実行する。
$ ls -l | awk -F . '{print $1}'
その結果は
total 8
drwxr-xr-x 2 Administrator なし 0 Jan 29 05:21 perl/
-rw-r--r-- 1 Administrator なし 10 Jan 14 15:53 sample
-rw-r--r-- 1 Administrator なし 10 Jan 30 00:41 sample2
サンプル3
以下のコマンドを実行する。
$ ls -l | awk '/sam/ {print $5,$9}'
その結果は
10 sample.txt
10 sample2.txt
サンプル4
以下のコマンドを実行する。(一行で記述。)
$ ls -l | awk 'BEGIN {print "START!"}
{total+=$5; print $9}
END {print "size total="total} '
その結果は
START!
perl/
sample.txt
sample2.txt
size total=20
最終更新:2006年01月30日 01:09