How to ignore beginning of line and parts of a line after filtering with grep

1

I try to filter out a trace output, located in /sys/kernel/debug/tracing/trace, which line content looks like this:

 kworker/4:2-1892  [004] ....  2186.662751: rtos_queue_send_from_isr_failed: tstamp:68702870649 queue:0x0b4b0e58
 kworker/4:2-1892  [004] ....  2186.662752: rtos_queue_send_from_isr_failed: tstamp:68702870787 queue:0x0b4b1c18
 kworker/4:2-1892  [004] ....  2186.662752: rtos_queue_send_failed: tstamp:68702872258 queue:0x0b4a7258
 kworker/4:2-1892  [004] ....  2186.662754: rtcpu_vinotify_event: tstamp:68702873824 tag:CSIMUX_STREAM channel:0xff frame:1 vi_tstamp:68702873242 data:0x00000001
 kworker/4:2-1892  [004] ....  2186.662755: rtcpu_vinotify_event: tstamp:68703270221 tag:CHANSEL_PXL_SOF channel:0x00 frame:45313 vi_tstamp:68703269252 data:0x00000001
 kworker/4:2-1892  [004] ....  2186.662755: rtcpu_vinotify_event: tstamp:68703270387 tag:ATOMP_FS channel:0x00 frame:45313 vi_tstamp:68703269257 data:0x00000000
 kworker/4:2-1892  [004] ....  2186.662756: rtcpu_vinotify_event: tstamp:68703270504 tag:CHANSEL_FAULT channel:0x00 frame:45313 vi_tstamp:68703269302 data:0x00000200
 kworker/4:2-1892  [004] ....  2186.662756: rtcpu_vinotify_event: tstamp:68703270903 tag:CSIMUX_STREAM channel:0xff frame:2 vi_tstamp:68703269326 data:0x00000001code:0404

In order to filter it, I want to get only events comming from rtcpu_vinotify_event, and which tag is not CSIMUX_STREAM or CHANSEL_PXL_SOF.

At the moment, I've achieved the following output

 kworker/4:2-1892  [004] ....  2186.662755: rtcpu_vinotify_event: tstamp:68703270387 tag:ATOMP_FS channel:0x00 frame:45313 vi_tstamp:68703269257 data:0x00000000
 kworker/4:2-1892  [004] ....  2186.662756: rtcpu_vinotify_event: tstamp:68703270504 tag:CHANSEL_FAULT channel:0x00 frame:45313 vi_tstamp:68703269302 data:0x00000200

with the following command

cat /sys/kernel/debug/tracing/trace | grep -v -e "rtos_queue_send_failed" -e "rtos_queue_send_from_isr_failed" -e "CSIMUX_STREAM" -e "CHANSEL_PXL_SOF"

Anyway, there is some irrelevant information in the output which I'd like to omit in the output (beginning of line until rtcpu_vinotify_event, and tstamp/vi_tstamp), so I'd get something like this:

 rtcpu_vinotify_event: tag:ATOMP_FS channel:0x00 frame:45313 data:0x00000000
 rtcpu_vinotify_event: tag:CHANSEL_FAULT channel:0x00 frame:45313 data:0x00000200

or, if the tstamps are complicated to avoid,

 rtcpu_vinotify_event: tstamp:68703270387 tag:ATOMP_FS channel:0x00 frame:45313 vi_tstamp:68703269257 data:0x00000000
 rtcpu_vinotify_event: tstamp:68703270504 tag:CHANSEL_FAULT channel:0x00 frame:45313 vi_tstamp:68703269302 data:0x00000200

Lastly, I've included rtcpu_vinotify_event messages by excluding rtos_queue_send_from_isr_failed and rtos_queue_send_failed messages. If there is a way to do it so that its not with exclusion, but inclusion of rtcpu_vinotify_event string, it would be much better, or if you find it easier with find, I don't have any preference.

bash
shell
grep
find
asked on Stack Overflow Jan 31, 2020 by EUS

2 Answers

1

Add

| cut -f3- -d:

to your command

For the inclusion-exclusion problem, why don't you just

| grep rtcpu_vinotify_event

instead of the excluding grep -v and its patterns?
The result would be

grep rtcpu_vinotify_event /sys/kernel/debug/tracing/trace | grep -v "CSIMUX_STREAM\|CHANSEL_PXL_SOF" | cut -f3- -d:

EDITED: (to remove also ts)

grep rtcpu_vinotify_event /sys/kernel/debug/tracing/trace | grep -v "CSIMUX_STREAM\|CHANSEL_PXL_SOF" | cut -f3,6- -d:
answered on Stack Overflow Jan 31, 2020 by franzisk • edited Jan 31, 2020 by franzisk
0

You could do two grep's, one for rtcpu_vinotify_event and then remove the matches for CSIMUX_STREAM and CHANSEL_PXL_SOF. The result is piped to sed to filter out the beginning of the line and tstamp / vi_tstamp.

grep 'rtcpu_vinotify_event' /sys/kernel/debug/tracing/trace | 
  grep -v 'CSIMUX_STREAM\|CHANSEL_PXL_SOF' | 
  sed 's/.*\(rtcpu_vinotify_event: \)tstamp:[0-9]* \(.*\)vi_tstamp:[0-9]* \(.*\)/\1\2\3/'
answered on Stack Overflow Jan 31, 2020 by Freddy

User contributions licensed under CC BY-SA 3.0