egrep -v # reverse match the lines
egrep
` 反引号
. 点号
' 单引号
" 双引号
Example: filter all the valid IP addresses in a Linux OS
#ip addr | egrep "([0-9]{1,3}.){3}[0-9]{1,3}/" | egrep -v '127.0.0|secondary' | awk '{print "ifconfig "$7" "$2" up"}' > ./ip-up.sh
#ip addr | egrep '“([0-9]{1,3}.){3}[0-9]{1,3}/” | secondary' | awk '{print "ifconfig "$8" "$2" up"}' >> ./ip-up.sh
#sed 's/up/down/g' ./ip-up.sh > ip-down.sh
grep不显示本身进程
命令:
ps aux | grep [s]shps aux | grep \[s]sh
因为grep进程的条目显示处理命令优先于正则表达式([s]ome_string)。当grep命令运行时,grep进程自身的条目不匹配,就没有包括在输出中了。
ps aux | grep ssh | grep -v "grep"
输出:
[root@localhost test]# ps aux|grep ssh
root 2720 0.0 0.0 62656 1212 ? Ss Nov02 0:00 /usr/sbin/sshd
root 16834 0.0 0.0 88088 3288 ? Ss 19:53 0:00 sshd: root@pts/0
root 16901 0.0 0.0 61180 764 pts/0 S+ 20:31 0:00 grep ssh
[root@localhost test]# ps aux|grep \[s]sh]
[root@localhost test]# ps aux|grep \[s]sh
root 2720 0.0 0.0 62656 1212 ? Ss Nov02 0:00 /usr/sbin/sshd
root 16834 0.0 0.0 88088 3288 ? Ss 19:53 0:00 sshd: root@pts/0
[root@localhost test]# ps aux | grep ssh | grep -v "grep"
root 2720 0.0 0.0 62656 1212 ? Ss Nov02 0:00 /usr/sbin/sshd
root 16834 0.0 0.0 88088 3288 ? Ss 19:53 0:00 sshd: root@pts/0
没有评论:
发表评论