当前位置: > shell编程 >

awk命令实例,awk命令用法

时间:2014-11-02 02:25来源:linux.it.net.cn 作者:it

awk命令用法:
 

复制代码代码示例:

df|awk '{print $0}'   
df|awk '{print $0}' >df.txt 
df|awk '{print $0}' |tee df.txt
awk '{print $0}' df.txt = awk '{print $0}' <df.txt
awk '{print $1,$2}' df.txt 
awk '{print $1"\t"$2}' df.txt
awk 'BEGIN {print "a  b\n-------------"} {print $1"\t"$2} END {print "-------------\n  end of report"}' df.txt
awk -F: '{if ($1~/wenhui/) print $0}' /etc/passwd
awk -F: '$1~/wenhui/ {print $0}' /etc/passwd
awk '/wenhui/' /etc/passwd

awk -F: '$1~/root/' /etc/passwd
awk -F: '$0~/root/' /etc/passwd
awk -F: '$7~/\/bin\/bash/' /etc/passwd("\"为转义符)
awk -F: '$7=="/bin/bash"' /etc/passwd
awk -F: '$7!="/bin/bash"' /etc/passwd
awk -F: '$3!=$4 {print $0}' /etc/passwd = awk -F: '{if ($3!=$4) print $0}' /etc/passwd

awk -F: '{if ($3>=$4) print $0}' /etc/passwd
awk -F: '$1 ~/...hui/' /etc/passwd
awk -F: '$1 ~/^w/' /etc/passwd
awk -F: '$1 ~/hui$/' /etc/passwd
awk -F: '$1~/(root|wenhui)/' /etc/passwd

awk -F: ' END {print NF}' /etc/passwd
awk -F: ' END {print NR}' /etc/passwd
awk -F: 'BEGIN {print NR}' /etc/passwd
awk -F: '{print NR,NF,$0} END {print "filename is " FILENAME}' /etc/passwd

**** awk -F/ 'END {print $NF}' /etc/passwd 和 awk -F/ 'END {print $NF}' /etc/passwd   注意区分
**** echo $PWD|awk -F/ '{print $NF}' cho $PWD|awk -F/ '{print NF}' 注意区分
awk -F: '{username=$1;shell=$7;if ($1=="wenhui") print username " de shell is "shell}' /etc/passwd

awk -F: '{if ($3>500 && $4<506) print $0}' /etc/passwd ===============    awk -F: '{if ($3>hao) print $0}' hao=500 /etc/passwd
awk -F: '{if ($1~/wenhui/)  $3=0;print $0}' haha|awk '$1~/wenhui/ {print $0}' =   awk -F: '{if ($1~/wenhui/)  {$3=0;print $0}}' haha 
awk -F: '{if ($1=="wenhui") $3=$3-100;print $1,$3}' haha 
awk -F: 'END {if ($1=="wenhui") $1="houzi";print $0}' haha
awk -F: ' {if ($1=="wenhui") {$1="houzi";print $0}}' haha
awk -F: '{if ($1~/wenhui/) {$8=$3+$4;print $1,$3,$4,$8}}' haha

awk '(tot+=$2); END{print "===========\ntotal is "tot }' df.txt
echo "88"|awk '{printf "%c\n",$0}
awk '{printf "%-40s %s\n",$1,$3}' df.txt 
w|awk '($1==user) {print $1" is connected to "$3}' user=$LOGNAME


(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容