簡體   English   中英

遍歷makefile中不包含某些文本的文件

[英]Loop through files which do not contain certain texts in makefile

我想瀏覽一下makefile一組文件:

alltest:    all
            for f in $(FILES); do \
                echo $$f; \
            done

我想編寫$(FILES)這樣它/abc/*.txt文件ERROR2其主體中不包含ERROR1ERROR2的文件。

太尋找一組文件中包含ERROR1ERROR2的文件,我使用find -iname '/abc/*.txt' | xargs grep -e "ERROR1" -e "ERROR2" find -iname '/abc/*.txt' | xargs grep -e "ERROR1" -e "ERROR2"

誰能告訴我如何做集合的補集,以及如何將shell命令集成到makefile中?

第一件事……這是您的想法和想要的嗎?

find -iname '/abc/*.txt'

在我的子目錄中找不到文件(在Mac OS X 10.8.5上)。 在哪里find . -iname '*.txt' find . -iname '*.txt'查找一些文件, find . -iname '/path/*.txt find . -iname '/path/*.txt -ipath . find . -iname '/path/*.txt產生輸出, find . -iname '/path/*.txt產生。 但是, find . -ipath '*/path/*.txt' find . -ipath '*/path/*.txt'會產生文件列表。 因此,暫時,我們將把您的find命令更正為:

find . -ipath '*/abc/*.txt'

接下來,您運行:

xargs grep -e "ERROR1" -e "ERROR2"

這將產生包含文件名和消息的行。 如果想要包含匹配項的文件名,則需要在命令中添加-l

find . -ipath '*/abc/*.txt' |
xargs grep -l -e "ERROR1" -e "ERROR2"

但是,您只想列出不匹配的文件。 為此,如果您具有GNU grep ,則可以使用-L選項:

find . -ipath '*/abc/*.txt' |
xargs grep -L -e "ERROR1" -e "ERROR2"

如果您沒有GNU grep ,那么您必須更加努力地工作:

find . -ipath '*/abc/*.txt' |
tee file.names |
xargs grep -l -e "ERROR1" -e "ERROR2" > matching.file.names
comm -23 file.names matching.file.names

tee命令捕獲文件file.names中文件名列表的副本(這種獨創性)。 grep命令捕獲文件名匹配的列表matching.file.names 兩個文件中的名稱將以相同的順序排列。 出現在那些file.names但不是在matching.file.names是你想要的人。 默認情況下, comm file.names matching.file.names命令將打印3列:僅在第一個文件中找到的行,僅在第二個文件中找到的行以及在兩個文件中都找到的行。 通過使用-23選項抑制第2列和第3列的輸出,我們僅獲得第一個文件中另一個文件中找不到的名稱-這就是您想要的列表。

您可以從哪里獲取清單,取決於您……

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM