强大的linux 命令

bin/run-example SparkPi 2>&1 | grep "Pi is"

  命令中的《2>&1》 用于将输出保存到stdout 里面,之后再对信息进行grep过滤 取出想要的信息。

ps -ef | grep asterisk | cut -c 9-15 | xargs kill -9

  一条命令将grep 出来的进程 kill 掉

 

https://blog.csdn.net/BabyFish13/article/details/79709028

 

 

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



 

posted @ 2018-09-11 16:24  Ray_lei  阅读(246)  评论(0编辑  收藏  举报