转自: http://blog.youkuaiyun.com/mrtitan/article/details/11068879
最近今天陆续学习了几条强大的Linux命令,记录下学习资料:
find+xargs+grep:http://www.cnblogs.com/skynet/archive/2010/12/25/1916873.html
awk:处理列格式文件利器
http://coolshell.cn/articles/9070.html
sed:处理行式文件利器
http://coolshell.cn/articles/9104.html
perl:正则匹配解析文件利器
给出一个例子:
cat rs-status.log | perl -lne 'if($_ =~/memstoreSizeMB=(\d+)/){if($1>0 &&$1<500){ print $1}}' | sort -n | perl -lne '$sum+=$_;$count++;$max=($max>$_)?$max:$_; }{$avg=$sum/$count;print "sum=$sum,max=$max,avg=$avg,count=$count"'
匹配上一行的数据
perl -lne 'if(/Recover RBW replica/){print $1 if( $last =~ /src: \/(.*):[0-9]+ dest/)} else{$last=$_}' /opt/log/hadoop/hadoop-hdfs-datanode-`hostname`.log
本文分享了Linux中find、xargs、grep、awk、sed、perl等强大命令的使用技巧,通过具体实例展示了如何高效处理列格式文件、行式文件及正则匹配解析文件,特别强调了Perl在复杂文本处理中的应用。
1184

被折叠的 条评论
为什么被折叠?



