使用 grep 過濾後如何忽略行首和行的一部分 (How to ignore beginning of line and parts of a line after filtering with grep)


問題描述

使用 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_failedrtos_queue_send_failed 消息。如果有辦法做到這一點,而不是排除,而是包含 rtcpu_vinotify_event 字符串,那會好得多,或者如果您發現使用 find 更容易,我沒有任何偏好。

rtos_queue_send_from_isr_failed</code> 和 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/'

(by EUSfranziskFreddy)

參考文件

  1. How to ignore beginning of line and parts of a line after filtering with grep (CC BY‑SA 2.5/3.0/4.0)

#find #shell #grep #bash






相關問題

禁止查找和 grep“無法打開”輸出 (Suppress find & grep "cannot open" output)

Cakephp 複雜查詢 (Cakephp complex query)

如何在 hasMany 關聯中使用 CakePHP 2 查找? (How to use CakePHP 2 find in a hasMany association?)

Jquery 響應 find() 失敗? (Jquery respond to find() fail?)

正則表達式記事本++ (RegEx Notepad++)

使用 VBA 在 MS Word 表格中查找和替換可變長度文本 (Find & replace variable length text in MS Word tables using VBA)

獲取子字符串周圍的字符數半徑 (Get set number radius of characters around substring)

僅在不到一天的文件中搜索字符串 (Search for a string only in files less than a day old)

c++ 查找和替換整個單詞 (c++ Find and replace whole word)

使用 grep 過濾後如何忽略行首和行的一部分 (How to ignore beginning of line and parts of a line after filtering with grep)

查找函數加上循環給出 1004 錯誤 (Find function couple with loop gives 1004 error)

VS Code 查找和替換:當我輸入 ctrl+h 時,有沒有辦法保留我以前的查找項? (VS Code find-and-replace: is there a way to keep my previous find term when I type ctrl+h?)







留言討論