ps -ef | grep bash
echo "ABC" | grep -i abc
ps -ef | grep bash | grep -v grep
echo "1234 7654" | grep -o "[0-9]4"
echo "1234 7654" | grep -oE "[0-9]4|76"
测试题
ps | awk 'BEGIN{print "start"}{print $0}END{print "end"}'
awk '/ 404 | 500 /' /tmp/nginx.log
echo '1
2
3
4
5' | awk '/2/,/4/'
echo '1
2
3
4
5' | awk '$0>3'
ps | awk 'NR>1'
ps | awk '{print $NF}'
echo $PATH | awk 'BEGIN{RS=":"}{print $0}' | grep -v "^$" | awk 'BEGIN{FS="\n";ORS=":"}{print $0}END{printf "\n" }'
echo '1,10
2,20
3,30' | awk 'BEGIN{a=0;FS=","}{a+=$2}END{print a,a/NR}'
awk 'BEGIN{print 33*20*76/200/3}'
echo "123|456_789" | awk 'BEGIN{FS="\\||_"}{print $2}'
echo "123|456_789" | awk "BEGIN{FS=\"\\\\||_\"}{print \$2}" #尽量使用单引号
测试题
pattern 表达式
action
ps | sed -n 1,3p
ps | sed 's/CMD/command/'
ps | sed -n '/ps/p'
echo '1
2
3
4
5' | sed -n '/3/,/4/p'
echo '1
2
3
4
5' | sed '/3/,/4/d'
ps | sed -e 's/CMD/command/' -e 's#00#20#g'
测试题