Suppose the file log.txt contains below content
[12] 03/31/21 08:33:30.080851 T(12581) _DBG message x 1
[12] 03/31/21 08:33:30.080851 T(34897) _DBG message y 1
[12] 03/31/21 08:33:31.241167 T(12344) _DBG message z 1
[12] 03/31/21 08:33:31.457612 T(34897) _DBG message y 2
test message line 2
test message line 3
test message line 4
[12] 03/31/21 08:33:31.78912 T(12344) _DBG message z 2
[12] 03/31/21 08:33:32.56341 T(34897) _DBG message y 3
[12] 03/31/21 08:33:33.12789 T(12581) _DBG message x 2
test message for x
[12] 03/31/21 08:33:33.78123 T(34897) _DBG message y 3
test message line 2
[12] 03/31/21 08:33:34.12342 T(12581) _DBG message x 3
[12] 03/31/21 08:33:34.56712 T(34897) _DBG message y 4
Desired output should be
[12] 03/31/21 08:33:30.080851 T(34897) _DBG message y 1
[12] 03/31/21 08:33:31.457612 T(34897) _DBG message y 2
test message line 2
test message line 3
test message line 4
[12] 03/31/21 08:33:32.56341 T(34897) _DBG message y 3
[12] 03/31/21 08:33:33.78123 T(34897) _DBG message y 3
test message line 2
[12] 03/31/21 08:33:34.56712 T(34897) _DBG message y 4
Given a thread ID, it should print the line + next few lines belong to that msg. Note that in the desired output, all other thread messages are removed.
I tried below sed command but it prints the next line also (which is different thread message)
sed -n -e '/T(34897)/,/_DBG/ p' log.txt
I tried other grep/awk/regex commands but couldn't get this done. Please help