2013-06-19 76 views
2

我使用grep從兩個不同的文件中的文件找到匹配的行。它發現匹配的文件從File1File2File3都很好,但是從有多個文件的那一刻起,它會打印出在該行旁邊找到的文件名。grep在多個文件打印匹配行與文件名

grep -w -f File1 File2 File3 

輸出:

File2: pattern

File2: pattern

File3: pattern

是否有避免File2:File3:打印的選項?

回答

5
grep --no-filename -w -f File1 File2 File3 
2

如果您使用的是UNIX系統,請參閱手冊頁。每當遇到問題時,您的第一步應該是man $programName。在這種情況下,man grep。看起來你想要「-h」選項。以下是手冊頁的摘錄:

-h, --no-filename 
      Suppress the prefixing of file names on output. This is the default when there is only one file (or only standard input) to search. 
相關問題