This is an old revision of the document!
$ awk '{print}' /etc/passwd $ awk '{print $0}' /etc/passwd
$ awk '/root/ {print $0}' /etc/passwd root:*:0:0:Charlie &:/root:/bin/csh toor:*:0:0:Bourne-again Superuser:/root: daemon:*:1:1:Owner of many system processes:/root:/usr/sbin/nologin
$ awk -F: '!/nologin/ {print $1}' /etc/passwd # $FreeBSD # root toor
$ awk -F: 'BEGIN {print "Users used csh"; count=0} /csh$/ {print $1; count++} END {print count " users"}' /etc/passwd
с какой строки начинается и от кого письмо
$ ee ex1.awk $ 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/uX String 1 From u0@server.class Tue Oct 18 10:05:44 2005 String 21 From u0@server.class Tue Oct 18 10:05:49 2005 String 41 From u5@server.class Tue Oct 18 10:05:49 2005 Переслать отдельное письмо: tail -n +21 /var/mail/uX | formail -1 -s sendmail val@bmstu.ru
$ vi wares.txt $ cat wares.txt table:34 car:24 apple:23 car:12 $ vi ex2.awk $ 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