常用运维命令_2
grep:
1 grep forest f.txt #文件查找 2 grep forest f.txt cpf.txt #多文件查找 3 grep 'log' /home/admin -r -n #目录下查找所有符合关键字的文件 4 cat f.txt | grep -i shopbase 5 grep 'shopbase' /home/admin -r -n --include *.{vm,java} #指定文件后缀 6 grep 'shopbase' /home/admin -r -n --exclude *.{vm,java} #反匹配 7 seq 10 | grep 5 -A 3 #上匹配 8 seq 10 | grep 5 -B 3 #下匹配 9 seq 10 | grep 5 -C 3 #上下匹配,平时用这个就妥了 10 cat f.txt | grep -c 'SHOPBASE'
awk:
1 awk '{print $4,$6}' f.txt 2 awk '{print NR,$0}' f.txt cpf.txt 3 awk '{print FNR,$0}' f.txt cpf.txt 4 awk '{print FNR,FILENAME,$0}' f.txt cpf.txt 5 awk '{print FILENAME,"NR="NR,"FNR="FNR,"$"NF"="$NF}' f.txt cpf.txt 6 echo 1:2:3:4 | awk -F: '{print $1,$2,$3,$4}' 7 awk '/ldb/ {print}' f.txt #匹配ldb 8 awk '!/ldb/ {print}' f.txt #不匹配ldb 9 awk '/ldb/ && /LISTEN/ {print}' f.txt #匹配ldb和LISTEN 10 awk '$5 ~ /ldb/ {print}' f.txt #第五列匹配ldb