Linux Shell经典面试题

时间:2021-06-02 11:35:11   收藏:0   阅读:0
查空行
awk /^$/{print NR} demo1.txt

求某一列的和
awk {sum+=$2} END {print "求和:"sum} demo2.txt

数字排序
sort -n -t   -k 2 demo3.txt
sort -t   -k 2nr demo3.txt

搜索指定目录下文件内容
grep -r 666 /root/ | cut -d : -f 1 | sort -u

筛选出单词长度大于3的单词
echo "I may not be able to change the past, but I can learn from it." | awk -F "[ ,.]" {for(i=1;i<=NF;i++){if(length($i)>3){print $i}}}

单词频次统计及排序
awk -F "[ ,.]" {for(i=1;i<=NF;i++){s[$i]++}} END {for(key in s){print key, s[key]}} demo5.txt | sort -k 2nr | head

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!