awk的OFS不能够直接在print中打印,需要用逗号分隔后打印 ,BEGIN定义域分隔符,输出分隔符
awk 'BEGIN{FS=":";OFS="=";} {print $3,$4;}' /etc/passwd
printf " %-10s\n" $1 $1以字符格式输入,且宽度为10,靠左对其
按照不同格式同时打印$1 $3
awk 'BEGIN {FS=":"}{printf "%-10s %10d\n", $1 ,$3}' /etc/passwd
2、awk BEGIN、END常用例子
cat /etc/
passwd |
awk -F
':' 'BEGIN {print "name,shell"} {print $1","$7} END {print "blue,/bin/nosh"}'
name,shell
root,/bin/bash
daemon,/bin/
sh
bin,/bin/
sh
sys,/bin/
sh
....
blue,/bin/nosh
3、awk -F ':' 'BEGIN {count=0;} {name[count] = $1;count++}; END{for (i = 0; i < NR; i++) print i,name[i]}' /etc/passwd
阅读(406) | 评论(0) | 转发(0) |