[root@localhost ~]# cat << EOF >> content.txt
hitesh engineer sales 30000
jayesh director account 25000
vyom manager purchase 20000
bhavesh engineer sales 30000
rajesh directory sales 40000
niraj clerk account 20000
jay peon purchase 23000
deep clerk sales 20000
EOF
NF
,从文件中删除所有空白行。例如,删除文件content.txt中的所有空白行。[root@localhost ~]# awk NF content.txt
[root@localhost ~]# awk '{ sub(/^[ \t]+/, ''); print }' content.txt
[root@localhost ~]# awk '{ sub(/[ \t]+$/, ''); print }' content.txt
[root@localhost ~]# awk '{ gsub(/^[ \t]+|[ \t]+$/, ''); print }' content.txt
[root@localhost ~]# awk '{ b[i++] = $0 } END { for (j=i-1; j>=0;) print b[j--] }' content.txt
[root@localhost ~]# awk 'NF { $0=++a ': ' $0 }; { print }' content.txt
[root@localhost ~]# awk '/engineer/{n++}; END {print n+0}' content.txt
[root@localhost ~]# awk '/engineer/' content.txt
[root@localhost ~]# awk '!/jayesh/' content.txt
[root@localhost ~]# awk '{gsub(/engineer/,'doctor')}{print}' content.txt
[root@localhost ~]# awk '{gsub(/jayesh|hitesh|bhavesh/ , 'mahesh'); print}' content.txt
[root@localhost ~]# df -h | awk '{printf('%-24s \t %-6s \t %-4s \n',$1,$4,$5)}'
[root@localhost ~]# netstat -ntu|awk '{print $5}'|cut -d: -f1|awk '/[0-9]/'|sort|uniq -c|sort -n
END
联系客服