【選印合乎指定條件的記錄】
$ vim adjust1.awk
$1 ~ /^A.*/ { $3 *= 1.05 } $3 < 100 { $3 = 100 }
{ printf(“%s %8s %dn”, $1, $2, $3) }
-> vim 命令模輸入 “:wq” (存檔離開)
$ awk -f adjust1.awk emp.txt
A125 Jenny 105
A341 Dan 115
P158 Max 130
P148 John 125
A123 Linda 100
$ vim reg.txt
Mary O.S. Arch. Discrete
Steve D.S. Algorithm Arch.
Wang Discrete Graphics O.S.
Lisa Graphics A.I.
Lily Discrete Algorithm
-> vim 命令模輸入 “:wq” (存檔離開)
$ vim course.awk
{ for (i=2; i
END { for (course in Number) printf(“%-10s %dn”, course, Number[course]) }
-> vim 命令模輸入 “:wq” (存檔離開)
$ awk -f course.awk reg.txt Graphics 2
O.S. 1
Discrete 2
D.S. 1
Arch. 1
Algorithm 1
$ vim count.awk
BEGIN {
while ( “who” | getline) n++
print n
}
-> vim 命令模輸入 “:wq” (存檔離開)
$ who
abc :0 2010-02-01 09:45
abc pts/0 2010-02-01 09:45 (:0)
abc pts/2 2010-02-01 09:46 (:0.0)
abc pts/3 2010-02-01 09:46 (:0.0)
abc pts/4 2010-02-01 09:47 (:0.0)
abc pts/5 2010-02-01 14:05 (:0.0)
$ awk -f count.awk
6
(ps.會視線上有幾人而有不同結果)
【資料參考來源】