After answering this question, I am now wondering the best way to further process the null-separated output of find -print0
.
The following command would search for a phrase in the first 10 files that find returns - maybe we don't want to search too many at one time.
find . -maxdepth 1 | head -10 | xargs grep "Specific Phrase"
However, if there are newlines or spaces in the filenames, this can become a challenge as they will mess up our xargs
command.
How could I write the following so it works - can I do this in bash or do I need to use a tool like awk
to break this string up at the nulls?
find . -maxdepth 1 -print0 | head -10 | xargs -0 grep "Specific Phrase"
It seems the other words I could use to describe this is how to change the field separator to be a null character.