标签:awk入门
1
2
3
4
5
6
|
[root@www ~] # last -n 5 root pts /1 192.168.13.1 Fri Nov 14 04:54 still logged in root pts /0 192.168.13.1 Fri Nov 14 01:19 still logged in reboot system boot 2.6.32-504.1.3.e Fri Nov 14 01:19 - 10:50 (10+09:31) root pts /1 192.168.13.1 Thu Nov 13 08:13 - crash (17:05) root pts /0 192.168.13.1 Thu Nov 13 07:19 - 10:12 (02:52) |
1
2
3
4
5
6
|
[root@www ~] # last -n 5 | awk ‘{print $1"\t"$3}‘ root 192.168.13.1 root 192.168.13.1 reboot boot root 192.168.13.1 root 192.168.13.1 |
1
2
3
4
5
6
|
[root@www ~] # head -5 /etc/passwd | awk -F: ‘{print "lines:"NR,$1,$7,"columes:"NF}‘ OFS="\t" lines:1 root /bin/bash columes:7 lines:2 bin /sbin/nologin columes:7 lines:3 daemon /sbin/nologin columes:7 lines:4 adm /sbin/nologin columes:7 lines:5 lp /sbin/nologin columes:7 |
1
2
3
4
5
6
|
[root@www ~] # head -5 /etc/passwd | awk -F: ‘{printf "%-15s %i\n",$1,$3}‘ root 0 bin 1 daemon 2 adm 3 lp 4 |
1
2
3
4
5
6
|
[root@www ~] # cat /etc/passwd | awk -F: ‘NR<=5{printf "%-15s %i\n",$1,$3}‘ root 0 bin 1 daemon 2 adm 3 lp 4 |
1
2
3
4
5
6
7
8
|
[root@www ~] # cat /etc/passwd | awk -F: ‘BEGIN{printf "%-15s %s\n","Username","ID"}NR<=5{printf "%-15s %i\n",$1,$3}END{print "========END========"}‘ Username ID root 0 bin 1 daemon 2 adm 3 lp 4 ========END======== |
标签:awk入门
原文地址:http://blog.csdn.net/androidmylove/article/details/41448169