shell 题

Posted xyqing525

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell 题相关的知识,希望对你有一定的参考价值。

(1)有一推主机地址:

a.baidu.com
.....
z.baidu.com

如何从这些数据中提取出.baidu.com之前的字母,如:a b...z?

#cat f1.txt | while read line; do echo ${line%%.*}; done

#awk -F‘.‘ ‘{print $1}‘ f1.txt

(2)处理以下文件内容,将域名取出并进行计数排序,如处理
oldboy.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

#cut -d‘/‘ -f3 f2.txt |sort| uniq -c

#awk -F‘/‘ ‘{print $3}‘ f2.txt | sort | uniq -c

#sed ‘s/^htt.*\/\///g‘ f2.txt | sed ‘s/\/.*html$//g‘  | sort | uniq -c

#cat f2.txt |tr ‘\/‘ ‘\n‘ | grep etiantian | sort | uniq -c

 














以上是关于shell 题的主要内容,如果未能解决你的问题,请参考以下文章