问题描述
这是错误日志的快照:
06:16:29,933 ERROR EmailRMManager$:45 - Exception In get Message
com.rabbitmq.client.AlreadyClosedException: clean connection shutdown; reason: Attempt to use closed channel
at com.rabbitmq.client.impl.AMQChannel.ensureIsOpen(AMQChannel.java:195)
at com.rabbitmq.client.impl.AMQChannel.rpc(AMQChannel.java:222)
at com.rabbitmq.client.impl.AMQChannel.rpc(AMQChannel.java:208)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:139)
at com.rabbitmq.client.impl.ChannelN.basicGet(ChannelN.java:645)
我执行以下命令:
cat foo.log | grep ERROR
可以通过以下方式获得OP:
06:16:29,933 ERROR EmailRMManager$:45 - Exception In get Message
我应该执行什么命令来获得输出
06:16:29,933 ERROR EmailRMManager$:45 - Exception In get Message
com.rabbitmq.client.AlreadyClosedException: clean connection shutdown; reason: Attempt to use closed channel
即也grep模式后的行?
最佳方法
只要做一个:
grep -A1 ERROR
-A1
告诉grep比赛后包括1行。 -B
在比赛前会包含几行,以防您也需要。
次佳方法
对于更便携的方式,有awk
awk '/ERROR/{n=NR+1} n>=NR' foo.log
或者,也许您希望所有缩进的行都跟随?
awk '/^[^[:blank:]]/{p=0} /ERROR/{p=1} p' foo.log