sed '/pattern/' filename
,找到符合 pattern 的資料。例如:找檔案 /etc/man.config 中含 nzip 及 bzip 的資料。
[dywang@dywmac zzz]$ grep -n '[nb]zip' /etc/man.config 136:.gz /usr/bin/gunzip -c 137:.bz2 /usr/bin/bzip2 -c -d [dywang@dywmac zzz]$ awk '/[nb]zip/' /etc/man.config .gz /usr/bin/gunzip -c .bz2 /usr/bin/bzip2 -c -d
[dywang@dywmac zzz]$ awk '/^C/' /etc/man.config CAT /bin/cat CMP /usr/libexec/man-cmp.sh COMPRESS /usr/bin/lzma COMPRESS_EXT .lzma
[dywang@dywmac zzz]$ cat sdata.txt no. name score1 score2 grade 11 dywang 81 12 A 152 linda 90 58 C 33 peter 72 95 C 4 rita 65 34 E 58 cora 5 85 D [dywang@dywmac zzz]$ awk '/\ [dp]/ {print $2 "\t" $5}' sdata.txt dywang A peter C
[dywang@dywmac zzz]$ awk '/[ABC]/ {count+=1} END {print "count="count}' sdata.txt count=3