《Linux Shell脚本攻略》 笔记 第四章:高效文本处理
./right.txt:1:1 yang man
hello world
./hello.c:int main()
sin.c:int main()
hello.cpp:int main()
a
b
--
a
b
root:x:0:0:/root:/bin/bash
bin:x:1:1:/bin:/sbin/nologin
root:
bin:x
daemo
adm:x
[root@localhost program_test]# cat word_freq.sh #!/bin/bash if [ $# -ne 1 ]; then echo "Usage: $0 filename" exit -1 fi filename=$1 egrep -o "\b[[:alpha:]]+\b" $filename | awk '{ count[$0]++ } END { printf("%-14s%s\n","word","Count");for(ind in count) { printf("%-14s%d\n",ind,count[ind]); } }'
this thisTHISTHIS
[this] [is] [an] [example]
11 abc 111 this 9 file contains 111 11 88 numbers 0000
[root@localhost program_test]# cat sed_data.txt | sed ‘s/\b[0-9]\{3\}\b/NUMBER3/g‘
11 abc NUMBER3 this 9 file contains NUMBER3 11 88 numbers 0000
begin...
line1
line2
end...
1+
2+
3+
4+
5+
==15
root /bin/bash
bin /sbin/nologin
daemon /sbin/nologin
[root@localhost program_test]# cat read_each_word.sh cat hello.c | ( while read line; do #echo $line; for word in $line; do #echo $word; for((i=0;i<${#word};i++)) do echo ${word:i:1} ; done done done )
4
5
6
[root@localhost program_test]# seq 9 | awk '{ lifo[NR]=$0; lno=NR } END { print "NR = " NR; for(;lno>-1;lno--) { print lifo[lno]; } }' NR = 9 9 8 7 6 5 4 3 2 1
作者:铭毅天下
转载请标明出处,原文地址:http://write.blog.csdn.net/postedit/42364823
如果感觉本文对您有帮助,请点击‘顶’支持一下,您的支持是我坚持写作最大的动力,谢谢!
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。