$ awk '{print}' /etc/passwd $ awk '{print $0}' /etc/passwd $ awk -F: '{print $1 " " $7}' /etc/passwd
$ awk '/^user/ {print $0}' /etc/passwd
$ awk -F: '!/sh$/ {print $1}' /etc/passwd
$ awk -F: 'BEGIN {print "Users used /bin/sh:"; count=0} /bin\/sh$/ {print $1; count++} END {print "Summary:" count " users"}' /etc/passwd
с какой строки начинается и от кого письмо
$ cat ex1.awk
BEGIN {st=1} /^$/ {st=1} /^From/ {if (st==1) {print "String " NR; print $0; st=0} } !/^$/ {st=0}
$ awk -f ex1.awk /var/mail/user1
String 1 From user1@host19.class.un Wed Feb 15 05:41:42 2012 String 19 From user2@host19.class.un Wed Feb 15 05:41:58 2012
Переслать отдельное письмо: tail -n +21 /var/mail/user1 | formail -1 -s sendmail val@bmstu.ru
$ cat list_count_ip.txt
32 172.16.1.5 15 172.16.1.3 11 172.16.1.4 24 172.16.1.1
$ COUNT=12 $ cat list_count_ip.txt | awk -v c=$COUNT '{if ($1 > c) print $2}'
$ cat wares.txt
table:34 car:24 apple:23 car:12
$ cat ex2.awk
{ M[$1]+=$2 } END { for (i in M) { print "sum " i "=" M[i] } }
$ awk -F: -f ex2.awk wares.txt
sum apple=23 sum car=36 sum table=34