ifconfig | grep -po '(?<=inet >*?<=inet)'
进阶部分 grep "main" . /etc/fstab-r --include *.{php,html} 2、grep "main" . -r --exclude "readme" grep "main" . -r --exclude-from filelist grep "string" . -r -n grep -l "root" /etc/fstab /etc/passwd grep -n "^[^a-zA-Z]" /etc/fstab grep -E "cd{1,2}3" /etc/fstab grep -Ev '^#|^$' /etc/fstab grep -P"^\s+\S" grep "nologin$" grwep -C 2 -E "^_?[a-zA-Z]+\b" /etc/init/functions 高级部分 习题四
awk :
附加题:一、打印以下用户
marry 2143 78 84 77jack 2321 66 78 45tom 2122 48 77 71mike 2537 87 97 95bob 2415 40 57 62 awk 'BEGIN{printf "%-10s%-8s%-6s%-10s%-10s%-10s%-10s\n","lineno.","name","no.",math","english","computer","total";print"------------------------------"; math=0;english=0;computer=0;total=0;}{printf "%-10s%-8s%-6s%-10s%-10s%-10s%-10s\n",NR,$1,$2,$3,$4,$5,$3+$4+$5;math+=$3;english+=$4;computer+=$5}END{print"---------------";printf "%-24s%-10s%-10s%-10s\n","total:",math,english,computer;printf "%-24s%-10s%-10s%-10s\n","AVG:",math/NR,English/NR,computer/NR;}' /tmp/test二、 netstate -tan :结合awk和netstat统计网络状态连接数 awk '/^tcp/ {++state[$NF]} END {for(key in state) print key,"\t",state[key]}'
答案:netstat -tan | grep "^tcp" |awk '{++state[$NF]}END{for (i in state)printf "%s:s\n",i,state[i]}'