gow icon indicating copy to clipboard operation
gow copied to clipboard

gfind with xargs grep fails if found file name had spaces

Open prakyg opened this issue 10 years ago • 1 comments

In my directory suppose I have a file "Uncle Fred Flits By.txt"

Now the following command fails- gfind . -name "*By.txt" | xargs grep "Pongo"

Output is: grep: ./Uncle: No such file or directory grep: Fred: No such file or directory grep: Flits: No such file or directory grep: By.txt: No such file or directory

prakyg avatar Jan 15 '16 20:01 prakyg

This is expected and you'll see the same behaviour on most *nix installations. It has to do with IFS (Internal Field Separator). You can get around this by issuing this instead:

gfind . -name "*By.txt" -print0| xargs -0 grep "Pongo"

gs11 avatar Jan 22 '16 14:01 gs11