for(i in array)
awk批量输出数组内容
awk 'BEGIN{a[0]=12306; a[1]="lidao"; a[2]="hello"; a[3]=123; for(i in a) print i,a[i]};'
统计下面每个URL出现的次数
-vFS=/ '{array[$3]++;}END{for (url in array) print url, array[url]}' url.txtawk -vFS=/ '{array[$3]++;}END{for (url in array) print url, array[url]}' url.txt | sort
awk '$9~[0-9][0-9][0-9]/{array[$9]++}END{for (i in array) print i, array[i]}' access.log | sort
awk循环
shell循环
awk循环
使用
for(i=1;i<=10;i++)
do
echo $i
done
for(i=1;i<=10;i++) {print i}
1-100求和
awk 'BEGIN{for(i=1;i<=100;i++){sum+=i;} print sum;}'
awk判断
磁盘利用率大于20%,则显示"disk not enough"
df -h | awk -F"[ %]+" 'NR>1{if($5>20){print "disk not enough", $1, $5,$NF}}'
awk使用条件判断时,第一个条件在{动作}前,后面还有条件判断用if
统计一段文本中,单词长度小于6的单词数量
Studying a subject that you feel pointless is never a fun or easy task. If you're study history, asking yourself the question "why is history important" is a very good first step. History is an essential part of human civilization. You will find something here that will arouse your interest, or get you thinking about the significance of history.
shen@ubuntu-vm:~/code/test$ awk -F"[ .\",]+" '{for(i=1;i<=NF;i++){print $i}}' en.txt StudyingasubjectthatyoufeelpointlessisneverafunoreasytaskIfyou'restudyhistoryaskingyourselfthequestionwhyishistoryimportantisaverygoodfirststepHistoryisanessentialpartofhumancivilizationYouwillfindsomethingherethatwillarouseyourinterestorgetyouthinkingaboutthesignificanceofhistoryshen@ubuntu-vm:~/code/test$ awk -F"[ .\",]+" '{for(i=1;i<=NF;i++){if(length($i)>6)print $i}}' en.txt StudyingsubjectpointlesshistoryyourselfquestionhistoryimportantHistoryessentialcivilizationsomethinginterestthinkingsignificancehistoryshen@ubuntu-vm:~/code/test$ awk -F"[ .\",]+" '{for(i=1;i<=NF;i++){if(length($i)>6) sum+=1}} END{print sum}' en.txt 16
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~