learningunix717
learningunix717

Reputation: 59

Find -exec awk redirect to file

I have the following script:

After finding files of specific extensions, it checks said files for whether they have a specific word or not.

find . -type d \( -name ThirdParty -o -name 3rdParty -o -name 3rd_party \) -prune -o -type f \( -name "*.java" -o -name "*.cs" -o -name "*.cpp" -o -name "*.cxx" -o -name "*.cc" -o -name "*.c" -o -name "*.h" -o -name "*.scala" -o -name "*.css" -o -name "*.js" \) -exec awk '/FOO/{f=1;exit} END{if (!f) printf "%s\0", FILENAME}' {} \; 

I want to output the names of all files with that word into a simple text file. I have tried doing

find . -type d \( -name ThirdParty -o -name 3rdParty -o -name 3rd_party \) -prune -o -type f \( -name "*.java" -o -name "*.cs" -o -name "*.cpp" -o -name "*.cxx" -o -name "*.cc" -o -name "*.c" -o -name "*.h" -o -name "*.scala" -o -name "*.css" -o -name "*.js" \) -exec awk '/FOO/{f=1;exit} END{if (!f) printf "%s\0", FILENAME}' {} \; > output.txt

However, my resulting output file is empty. Thanks.

Upvotes: 0

Views: 112

Answers (1)

downtheroad
downtheroad

Reputation: 419

maybe with xargs:

find . -type d \( -name ThirdParty -o -name 3rdParty -o -name 3rd_party \) \
-prune -o -type f \( -name "*.java" -o -name "*.cs" -o -name "*.cpp" -o -name "*.cxx" \
-o -name "*.cc" -o -name "*.c" -o -name "*.h" -o -name "*.scala" -o -name "*.css" \
-o -name "*.js" \) | xargs grep -L word > list_of_files_missing_word.txt

Upvotes: 1

Related Questions