This is a snapshot of error log:
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)
I do the following command:
cat foo.log | grep ERROR
to get an OP as:
06:16:29,933 ERROR EmailRMManager$:45 - Exception In get Message
What command should I execute to get the output as
06:16:29,933 ERROR EmailRMManager$:45 - Exception In get Message
com.rabbitmq.client.AlreadyClosedException: clean connection shutdown; reason: Attempt to use closed channel
ie, also grep the line(s) after the pattern?
Just do a:
The
-A1
tells grep to include 1 line after the match.-B
includes lines before the match, in case you need that too.For a more portable way, there's awk
Or maybe you want all the indented lines following?
I have found this solution:
Where
(\n(?=\s).*?)*
means:\n
find next line(?=\s)
where is starts from whitespace character.*?
until end of line(...)*
Find such lines multiple timesPS. You may turf this pattern
\ncom\.rabbitmq.*?
if second line begins from whitespace\s
For this simple task a simple way is:
Note: no whitespace may be given between the option and its argument.