将文件中的域名取出并进行排序

[root@tomcat ~]# cat xingfujie.log
http://www.etiantian.org/index.html
http://www.etiantian.org/1.html
http://post.etiantian.org/index.html
http://mp3.etiantian.org/index.html
http://www.etiantian.org/3.html
http://post.etiantian.org/2.html

范例1:
[root@tomcat ~]# cut -d "/" -f 3 xingfujie.log |sort|uniq -c
      1 mp3.etiantian.org
      2 post.etiantian.org
      3 www.etiantian.org
范例2:
[root@tomcat ~]# awk -F "/" '{print $3}' xingfujie.log |sort|uniq -c
      1 mp3.etiantian.org
      2 post.etiantian.org
      3 www.etiantian.org
范例3:
[root@tomcat ~]# sed 's/^htt.*\/\///g' xingfujie.log |sed 's/\/.*html$//g'|sort|uniq -c
      1 mp3.etiantian.org
      2 post.etiantian.org
      3 www.etiantian.org
范例4:
[root@tomcat ~]# cat xingfujie.log |tr "\/" "\n"|grep etiantian|sort|uniq -c
      1 mp3.etiantian.org
      2 post.etiantian.org
      3 www.etiantian.org
范例5:
[root@tomcat ~]# cut -d "/" -f 3 xingfujie.log|awk '{++S[$1]} END {for(key in S)print key,S[key]}'|sort -k2|uniq -c
      1 mp3.etiantian.org 1
      1 post.etiantian.org 2
      1 www.etiantian.org 3
范例6:
[root@tomcat ~]# awk -F "/" '{++S[$3]} END {for(key in S)print key,S[key]}' xingfujie.log |sort -k2|uniq -c
      1 mp3.etiantian.org 1
      1 post.etiantian.org 2
      1 www.etiantian.org 3

你可能感兴趣的:(正则表达式,职场,域名,休闲,域名取出)