1

何百もの xml ファイルにいくつかのキーワードが存在するかどうかを検索したいのですが、次のスクリプトを使用してこれを処理したいと考えています。

#!/usr/local/bin/bash

find . -name '*.xml' |xargs egrep -n "HERE IS LONG LIST(word1|word2|...)" > result

次のようなエラー メッセージが表示されました。

xargs: a single arg was greater than the max arglist size of 2048 characters

そのため、長いリストを 3 つの部分に変更すると、次のようになります。

#!/usr/local/bin/bash

find . -name '*.xml' |xargs egrep -n "LIST_1" > result
find . -name '*.xml' |xargs egrep -n "LIST_2" >> result
find . -name '*.xml' |xargs egrep -n "LIST_3" >> result

パターンリストの分離を避けるためにこれを処理するより良い方法はありますか?

4

2 に答える 2

6

より良いアプローチは、一致するすべてのパターンをファイルに保存し、-fスイッチで再帰的な grep を使用することです。

grep -n -f patternFile -R --include=*.xml .
于 2013-06-24T09:46:45.150 に答える