> output2.txt
cd # some directory i'm trying to search
find views/shared -type f -name "*.js" -print0 | while IFS= read -r -d $'\0' line; do
echo -n "${line%.js}" | tee -a ~/Documents/counter/output2.txt
grep -lr "${line%.js}" . | wc -l | tee -a ~/Documents/counter/output2.txt # produce a count of occurrences
regex='[a-zA-Z]+.extend'
grep -f $line $regex
grep -lr "${line%.js}" . | tee -a ~/Documents/counter/output2.txt # produce a list of occurrences
done
商品を返す
grep: brackets ([ ]) not balanced
オンラインで見たすべての例は、ここに問題がないことを示しているようで、混乱しています。
角かっこは確かにバランスを取っていませんか?
ベストアンサー1
あなたの質問は-f
オプションです。検索するファイルを指定する代わりに、-f
パターンリストを読み取るファイルを指定してください。 OS X grepのマニュアルページでこれについて説明します。わからない:
-f file, --file=file
Read one or more newline separated patterns from file. Empty pattern lines match every input
line. Newlines are not considered part of a pattern. If file is empty, nothing is matched.
GNU grepのヘルプは実際には簡単です。
$ grep --help | grep -- '-f,'
-f, --file=FILE obtain PATTERN from FILE
$
-f
GNU grepのマニュアルページによると、この動作は次のようになります。specified by POSIX.
あなたの修正はあなたの回線を変更することです。
grep -f $line $regex
到着する:
egrep "$regex" -- "$line"
- 拡張正規表現を使用しているので、
egrep
またはgrep -E
- これにより、変数のすべてのオプションが解析されるのを
--
防ぎます。たとえば、 ""という名前のファイルからユーザーを保護します。grep
$line
-r funnyname.js