代码:: |
cat test1.dat one 123-321 234/22 a two 344-637 726/28 c three 273-287 287/97 d four 872-872 282/20 c |
代码:: |
awk '{print $2}' test1.dat 123-321 344-637 273-287 872-872 |
代码:: |
>,<,>=,<=,==,!= |
代码:: |
"Xplore" ~/or/ |
代码:: |
$cat count.awk BEGIN{ print "now,begin statistic the lines of file "; count=1; } { print "this is the " count " line"; count++; } END{ print "this is the end of file"; } $ awk -f count.awk test1.dat now,begin statistic the lines of file this is the 1 line this is the 2 line this is the 3 line this is the 4 line this is the end of file |
代码:: |
$awk '{if (NF>max) max=NF} END{print max} ' test1.dat 4 |
代码:: |
$ awk 'NF>0' test1.dat one 123-321 234/22 a two 344-637 726/28 c three 273-287 287/97 d four 872-872 282/20 c |
代码:: |
$ awk 'NR %2 ==0' test1.dat two 344-637 726/28 c four 872-872 282/20 c |
代码:: |
$ awk 'BEGIN{for (i=1;i<7;i++) print int(101*rand())}' 24 29 85 15 59 19 |
代码:: |
]$ ls -l |awk '{x+=$5}; END{print x}' 15827 |
代码:: |
$ awk 'BEGIN{FS=":";} {print $1 |"sort" }' /etc/passwd adm apache bin daemon dbus desktop ftp games gdm gopher guest halt lp mailnull mlsx mysql news nfsnobody nobody nscd ntp operator pcap plone root rpc rpcuser rpm shutdown smmsp squid sshd sync uucp vcsa webalizer wpm xfs |
代码:: |
$ awk 'END{print "total",NR,"lines"}' test1.dat total 4 lines |
代码:: |
1: root:x:0:0:root:/root:/bin/bash 2: bin:x:1:1:bin:/bin:/sbin/nologin 3: daemon:x:2:2:daemon:/sbin:/sbin/nologin 4: adm:x:3:4:adm:/var/adm:/sbin/nologin 5: lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin 6: sync:x:5:0:sync:/sbin:/bin/sync 7: shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown 8: halt:x:7:0:halt:/sbin:/sbin/halt 9: mail:x:8:12:mail:/var/spool/mail:/sbin/nologin 10: news:x:9:13:news:/etc/news: 11: uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin 12: operator:x:11:0:operator:/root:/sbin/nologin 13: games:x:12:100:games:/usr/games:/sbin/nologin 14: gopher:x:13:30:gopher:/var/gopher:/sbin/nologin 15: ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin 16: nobody:x:99:99:Nobody:/:/sbin/nologin 17: rpm:x:37:37::/var/lib/rpm:/bin/bash 18: vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin 19: nscd:x:28:28:NSCD Daemon:/:/sbin/nologin 20: sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin 21: rpc:x:32:32:Portmapper RPC user:/:/sbin/nologin 22: rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin 23: nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin 24: mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin 25: smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin 26: pcap:x:77:77::/var/arpwatch:/sbin/nologin 27: ntp:x:38:38::/etc/ntp:/sbin/nologin 28: gdm:x:42:42::/var/gdm:/sbin/nologin 29: desktop:x:80:80:desktop:/var/lib/menu/kde:/sbin/nologin 30: mlsx:x:500:48:weiguozhao:/home/mlsx:/bin/bash 31: apache:x:48:0:Apache:/var/www:/sbin/nologin 32: webalizer:x:67:67:Webalizer:/var/www/html/usage:/sbin/nologin 33: guest:x:501:501::/home/guest:/bin/bash 34: wpm:x:502:502::/home/wpm:/bin/bash 35: dbus:x:81:81:System message bus:/:/sbin/nologin 36: plone:x:101:102:Plone User:/var/lib/plone2/main:/bin/false 37: squid:x:23:23::/var/spool/squid:/sbin/nologin 38: xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin 39: mysql:x:103:104:MySQL server:/var/lib/mysql:/bin/bash |
代码:: |
$ awk '/one/{print $0}' test1.dat one 123-321 234/22 a |
代码:: |
$ awk 'BEGIN{FS=":";} {if ($3>499) print $1 "@cie.xtu.edu.cn"}' /etc/passwd nfsnobody@cie.xtu.edu.cn mlsx@cie.xtu.edu.cn guest@cie.xtu.edu.cn wpm@cie.xtu.edu.cn |
欢迎光临 MariaDB社区 (http://123.56.88.72/) | Powered by Discuz! X3.2 |