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


問題描述

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

I was given this syntax by user phi

find . | awk '!/((\.jpeg)|(\.jpg)|(\.png))$/ {print $0;}' | xargs grep "B206"

I would like to suppress the output of grep: can't open..... and find: cannot open lines from the results. sample output to be ignored:

grep: can't open ./cisc/.xdbhist
find: cannot open ./cisc/.ssh

參考解法

方法 1:

Have you tried redirecting stderr to /dev/null ? 

2>/dev/null

So the above redirects stream no.2 (which is stderr) to /dev/null. That's shell dependent, but the above should work for most. Because find and grep are different processes, you may have to do it for both, or (perhaps) execute in a subshell. e.g.

find ... 2>/dev/null | xargs grep ... 2>/dev/null

Here's a reference to some documentation on bash redirection. Unless you're using csh, this should work for most.

方法 2:

The option flag grep -s will suppress these messages for the grep command 

(by CheeseConQuesoBrian Agnewtravellingfelix)

參考文件

  1. Suppress find & grep "cannot open" output (CC BY-SA 3.0/4.0)

#filtering #find #unix #grep






相關問題

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

directx10 中的精靈和紋理過濾 (Sprites in directx10 and texture filtering)

使用 Lucene 統計分類結果 (Using Lucene to count results in categories)

根據 URL 變量過濾 HTML 內容 (Filtering HTML content based on URL Variable)

網格列包含 int64 值,但過濾器顯示字符串並且不起作用/ (Grid column contains int64 values but filter shows strings and doesn't work/)

angularjs中的雙重過濾 (dual filtering in angularjs)

按序列順序過濾 Birt 表 (Filter in serial order for Birt tables)

日期的 Drupal 8 上下文過濾器 (Drupal 8 contextual filter for date)

在VB中過濾一個wpf collectionviewsource? (Filter a wpf collectionviewsource in VB?)

遍歷對象並返回匹配的鍵/值 (Traverse object and return matching key / values)

過濾Python列表時出現意外輸出:我做錯了什麼? (Unexpected output when filtering Python list: What am I doing wrong?)

角度:錯誤 RangeError:超出最大調用堆棧大小 (ANGULAR: ERROR RangeError: Maximum call stack size exceeded)







留言討論