shell使用tips

shell for循环
引用
for m in `cat m.md`;do echo $m;done


shell互操作
引用
echo choice:$'\n' 1.a $'\n' 2.b $'\n' 3.b;read x;echo $x


查文件并且处理
引用
find /home/admin/logs/ -iname error.log | xargs cat

引用
find /home/admin/data2/zkLog/version-2 -mtime +3|xargs rm -f {}


awk值的条件判定,并打印
引用
cat /tmp/xxx | awk -F, '{source=substr($7,11,1);target=substr($8,14,1);if(source>target)print $7,$8}'


去掉某个字符
引用
sed 's/\"//g'


列求和附带字符串处理
引用
cat /tmp/xxx |awk 'BEGIN{total=0}{v=substr($4,2);total+=v}END{print total}'

猜你喜欢

转载自bucketli.iteye.com/blog/2252970