問題描述
使用 grep 過濾後如何忽略行首和行的一部分 (How to ignore beginning of line and parts of a line after filtering with grep)
/p>
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
或者,如果 tstamps
很難避免,
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
最後,我通過排除 rtcpu_vinotify_event
消息來包含 rtos_queue_send_from_isr_failed
和 rtos_queue_send_failed
消息。如果有辦法做到這一點,而不是排除,而是包含 rtcpu_vinotify_event
字符串,那會好得多,或者如果您發現使用 find
更容易,我沒有任何偏好。
rtos_queue_send_failed
消息。如果有辦法做到這一點,而不是排除,而是包含 rtcpu_vinotify_event
字符串,那會好得多,或者如果您發現使用 find
更容易,我沒有任何偏好。</p> rtos_queue_send_from_isr_failed</code> 和 rtos_queue_send_failed
消息。如果有辦法做到這一點,而不是排除,而是包含 rtcpu_vinotify_event
字符串,那會好得多,或者如果您發現使用 find
更容易,我沒有任何偏好。</p> 參考解法
方法 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:
方法 2:
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/'