日期:2014-05-16  浏览次数:20965 次

请问:用grep怎样只显示记录的其中几列啊?比如:
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怎么写啊?

------解决方案--------------------
不好意思,打错了,应该是
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} '