每日一题20180325

阅读:470 2019-03-19 15:04:31 来源:新网

处理以下文件内容,将域名取出并根据域名进行计数排序处理:(百度和sohu面试题)

http://www.etiantian.org/index.htmlhttp://www.etiantian.org/1.htmlhttp://post.etiantian.org/index.htmlhttp://mp3.etiantian.org/index.htmlhttp://www.etiantian.org/3.htmlhttp://post.etiantian.org/2.html

要求结果

mp3.etiantian.org1post.etiantian.org2www.etiantian.org31.2

统计企业工作中高并发web服务器不同网络连接状态对应的数量

protorecv-qsend-qlocal-addressforeign-addressstatetcp000.0.0.0:33060.0.0.0:*listentcp000.0.0.0:800.0.0.0:*listentcp00127.0.0.1:90000.0.0.0:*listentcp00coolshell.cn:80124.205.5.146:18245time_waittcp00coolshell.cn:8061.140.101.185:37538fin_wait2tcp00coolshell.cn:80110.194.134.189:1032establishedtcp00coolshell.cn:80123.169.124.111:49809establishedtcp00coolshell.cn:80116.234.127.77:11502fin_wait2tcp00coolshell.cn:80123.169.124.111:49829establishedtcp00coolshell.cn:80183.60.215.36:36970time_waittcp04166coolshell.cn:8061.148.242.38:30901establishedtcp01coolshell.cn:80124.152.181.209:26825fin_wait1tcp00coolshell.cn:80110.194.134.189:4796establishedtcp00coolshell.cn:80183.60.212.163:51082time_waittcp01coolshell.cn:80208.115.113.92:50601last_acktcp00coolshell.cn:80123.169.124.111:49840establishedtcp00coolshell.cn:80117.136.20.85:50025fin_wait2tcp00:::22:::*listen1.3

分析图片服务日志,把日志(每个图片访问次数*图片大小的总和)排行,取top10,也就是计算每个url的总访问大小

59.33.26.105--[08/dec/2010:15:43:56+0800]"get/static/images/photos/2.jpghttp/1.1"20011299"http://oldboy.blog.51cto.com/static/web/column/17/index.shtml?courseid=43""mozilla/4.0(compatible;msie6.0;windowsnt5.1;sv1;.netclr2.0.50727;.netclr3.0.4506.2152;.netclr3.5.30729)"59.33.26.105--[08/dec/2010:15:43:56+0800]"get/static/images/photos/2.jpghttp/1.1"20011299"http://oldboy.blog.51cto.com/static/web/column/17/index.shtml?courseid=43""mozilla/4.0(compatible;msie6.0;windowsnt5.1;sv1;.netclr2.0.50727;.netclr3.0.4506.2152;.netclr3.5.30729)"59.33.26.105--[08/dec/2010:15:44:02+0800]"get/static/flex/vedioloading.swfhttp/1.1"2003583"http://oldboy.blog.51cto.com/static/flex/adobevideoplayer.swf?width=590&height=328&url=/`dynamic`/2""mozilla/4.0(compatible;msie6.0;windowsnt5.1;sv1;.netclr2.0.50727;.netclr3.0.4506.2152;.netclr3.5.30729)"124.115.4.18--[08/dec/2010:15:44:15+0800]"get/?=http/1.1"20046232"-""-"124.115.4.18--[08/dec/2010:15:44:25+0800]"get/static/js/web_js.jshttp/1.1"2004460"-""-"124.115.4.18--[08/dec/2010:15:44:25+0800]"get/static/js/jquery.lazyload.jshttp/1.1"2001627"-""-"1.4

假如现在有个文本,格式如下:

a1b3c2d7b5a3g2f6d9

即左边是随机字母,右边是随机数字,要求写个脚本使其输出格式为:

a4b8c2d16f6g2

即将相同的字母后面的数字加在一起,按字母的顺序输出。

1、按单词出现频率降序排序!

2、按字母出现频率降序排序!

thesquidprojectprovidesanumberofresourcestoassistusersdesign,implementandsupportsquidinstallations.pleasebrowsethedocumentationandsupportsectionsformoreinfomation二、答案2.1

awk-f"/+"'{host[$2]++}end{for(iinhost)printi,host[i]}'a.txt|sort-rnk2

分析:

#01找出域名awk-f参数指定分割符"/+"表示以/或连续多个//为分割符#02域名计数awk命令结构begin{}{}end{}定义数组host[$2]以域名为索引,数组的值为域名的统计数据循环结束后输出域名和域名统计数据#03排序sort-r参数表示倒序-n参数表示按数字排序-k2表示按第二列排序2.2

awk'{print$nf}'a.txt|uniq-c

分析:

nf表示遍历的当前行的字段个数$nf就表示最后一个字段的值,最后一个字段的值就是网络状态uniq-c去重并计数2.3

awk'nf>0{url[$7]+=$10}end{for(iinurl)printi,url[i]}'a.txt|sort-rnk2|head-10

分析:

awk默认分割符是空格,第7列是访问的url,第10列是访问资源的大小由于日志有空行,nf>0表示该行没有项,即空行head-10表示取前10行2.4

awk'{alpha[$1]+=$2}end{for(iinalpha)printi,alpha[i]}'a.txt

分析:和1.1思路类似

#升序排cata.txt|xargs-n1|awk'{word[$1]++}end{for(iinword)printi,word[i]}'|sort-nk2#降序cata.txt|xargs-n1|awk'{word[$1]++}end{for(iinword)printi,word[i]}'|sort-nrk2

分析:

一行转多行xargs-n1表示每行一个每行3个就-n3-dx表示把x作为分隔符,默认是空格三、参考

老男孩教育每日一题-2017年3月31日-awk数组统计

相关文章
{{ v.title }}
{{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
你可能感兴趣
推荐阅读 更多>
推荐商标

{{ v.name }}

{{ v.cls }}类

立即购买 联系客服