This is an old revision of the document!
$ 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
с какой строки начинается и от кого письмо
$ 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