I often want to write commands like this (in zsh
, if it's relevant):
find <somebasedirectory> |
grep stringinfilenamesIwant |
grep -v stringinfilesnamesIdont |
xargs dosomecommand
(or more complex combinations of greps)
In recent years find
has added the -print0
switch, and xargs has added -0
, which allow handling of files with spaces in the name in an elegant way by null-terminating filenames instead, allowing for this:
find <somebasedirectory> -print0 | xargs -0 dosomecommand
However, grep
(at least the version I have, GNU grep 2.10 on Ubuntu), doesn't seem to have an equivalent to consume and generate null-terminated lines; it has --null
, but that only seems related to using -l
to output names when searching in files directly with grep.
Is there an equivalent option or combination of options I can use with grep? Alternatively, is there an easy and elegant way to express my pipe of commands simply using find's -regex
, or perhaps Perl?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…