+ -
当前位置:首页 → 问答吧 → 打印匹配字段sendmail: ?

打印匹配字段sendmail: ?

时间:2011-04-22

来源:互联网

本帖最后由 shot 于 2011-04-22 13:30 编辑

root      4176     1  0 Apr18 ?        00:00:00 sendmail:    accepting connections
root      4176     1  0 Apr18 ?        00:00:00 sendlll:    accepting connections
root      4176     1  0 Apr18 ?        00:00:00 sendmfdfail:    accepting connections
root      4176     1  0 Apr18 ?        00:00:00 sendmadfdfdil:    accepting connections


请问如何提取sendmail: 这个字段?

作者: shot   发布时间: 2011-04-22

awk -F: '{print $NF}' file

作者: greysky-zfj   发布时间: 2011-04-22

回复 shot


    grep -Po 'send[^:]*:'

作者: yinyuemi   发布时间: 2011-04-22

$NF 是打印最后一列啊,如果是这样了?

root     15635     1  0  2010 ?        00:00:05 /opt/TT/LC/bin/linux-ix86/mrt/lc -g test.sky.com

如何打印出:
/opt/TT/LC/bin/linux-ix86/mrt/lc

作者: shot   发布时间: 2011-04-22

回复 shot


    grep -Po '(?<=:[0-9][0-9] )[^ ]*'

作者: yinyuemi   发布时间: 2011-04-22

能不能这样?

找到opt前的/, 就是以/ 开头的,  然后比较这个串是否含有lc  ,  如果有则打印/opt/TT/LC/bin/linux-ix86/mrt/lc  ?

谢谢楼上各位热心

作者: shot   发布时间: 2011-04-22

回复 shot


    这个意思:
grep -Po '(?<=:[0-9][0-9] ).*lc[^ ]*'

作者: yinyuemi   发布时间: 2011-04-22