当前位置: 技术问答>linux和unix
请问:用grep怎样只显示记录的其中几列啊?比如:
来源: 互联网 发布时间:2016-02-29
本文导语: Apr 16 16:18:35 localhost nagios: Caught SIGTERM, shutting down... Apr 16 16:18:35 localhost nagios: Successfully shutdown... (PID=748) Apr 16 16:18:38 localhost nagios: Nagios 2.8 starting... (PID=8503) Apr 16 16:18:38 localhost nagios: LOG VERSION: 2....
Apr 16 16:18:35 localhost nagios: Caught SIGTERM, shutting down...
Apr 16 16:18:35 localhost nagios: Successfully shutdown... (PID=748)
Apr 16 16:18:38 localhost nagios: Nagios 2.8 starting... (PID=8503)
Apr 16 16:18:38 localhost nagios: LOG VERSION: 2.0
Apr 16 16:18:38 localhost nagios: Finished daemonizing... (New PID=8504)
Apr 16 17:03:15 localhost nagios: Caught SIGTERM, shutting down...
Apr 16 17:03:15 localhost nagios: Successfully shutdown... (PID=8504)
Apr 16 17:03:18 localhost nagios: Nagios 2.8 starting... (PID=9338)
我只想显示第三列为16:18:38 的行 的第五,第六项,
这用grep怎么写啊?
Apr 16 16:18:35 localhost nagios: Successfully shutdown... (PID=748)
Apr 16 16:18:38 localhost nagios: Nagios 2.8 starting... (PID=8503)
Apr 16 16:18:38 localhost nagios: LOG VERSION: 2.0
Apr 16 16:18:38 localhost nagios: Finished daemonizing... (New PID=8504)
Apr 16 17:03:15 localhost nagios: Caught SIGTERM, shutting down...
Apr 16 17:03:15 localhost nagios: Successfully shutdown... (PID=8504)
Apr 16 17:03:18 localhost nagios: Nagios 2.8 starting... (PID=9338)
我只想显示第三列为16:18:38 的行 的第五,第六项,
这用grep怎么写啊?
|
不好意思,打错了,应该是
grep `cat filename | awk '{print $3};' | grep "16:18:38" | head -n 1` filename
grep `cat filename | awk '{print $3};' | grep "16:18:38" | head -n 1` filename
|
楼上的还是不对
应该是
cat filename | awk '{print $3,$5,$6}' | grep "^16:18:38" | awk '{print $2,$3}'
应该是
cat filename | awk '{print $3,$5,$6}' | grep "^16:18:38" | awk '{print $2,$3}'