I am trying to find a specific PID in a logcat and print all lines until the next empty line. The logcat looks something like this.
[ 07-17 11:15:14.003 483: 515 D/SensorService ]
Message
[ 07-17 11:15:15.300 20220:20225 D/dalvikvm ]
Message
[ 07-17 11:15:17.519 483: 515 D/SensorService ]
Message
What I have found searching for a solution to this problem is this:
sed -n '/pattern/,/^$/p' logcat
In this example I would like to do this
sed -n '/20220/,/^$/p' logcat
However, I cannot get this to work. It actually prints the entire logcat instead of filtering it. When I do execute
sed -n '/pattern/p' logcat
it works just as expected (like grep) but only taking the first line. In my understanding ^ represents the beginning of a line and $ the end, thus making ^$ an empty line.
I would be grateful for any inputs in how to solve this problem. Thank you.
Through awk,
$ awk '/20220/{p=1}/^ *$/{p=0}p' file
[ 07-17 11:15:15.300 20220:20225 D/dalvikvm ]
Message
Through sed,
$ sed -n '/20220/,/^ *$/p' file
[ 07-17 11:15:15.300 20220:20225 D/dalvikvm ]
Message
But the above sed command prints also the blank line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With