Reputation: 2583
Where does grep: : No such file or directory
come from when I pass a filename to grep with xargs?
⋊> ~/.v/bundle find . -name config | grep ".git" | xargs grep "url" {} 11:07:46
grep: : No such file or directory
./Dockerfile.vim/.git/config: url = https://github.com/ekalinin/Dockerfile.vim.git
./nerdcommenter/.git/config: url = https://github.com/scrooloose/nerdcommenter.git
Though there are no empty lines or something like that when I do
⋊> ~/.v/bundle find . -name config | grep ".git" 11:08:30
./Dockerfile.vim/.git/config
./nerdcommenter/.git/config
And how to avoid it?
I know that I can skip the first line with something like awk 'NR>1'
but would like to understand the cause of the issue.
Thank you.
P.S. I'm on Mac.
Upvotes: 2
Views: 508
Reputation: 158020
Hard to say what is going wrong on your site. I've tried to reproduce the error, having .vim/bundle
as well, but I couldn't reproduce it.
Anyhow, I suggest to simplify the command to:
find . -wholename '*/.git/config' -exec grep -H url {} +
xargs
is not required any more since find
supports the +
syntax. This is at least true for GNU, BSD (MacOS) and busybox versions of find
.
Upvotes: 2
Reputation: 17735
There is no need to add {}
(unlike find -exec
)
~/.v/bundle find . -name config | grep ".git" | xargs grep "url"
should work.
Or even better (just in case of file or directory names containing spaces or unusual characters) :
~/.v/bundle find . -name config -print0 | grep -z ".git" | xargs --null grep "url"
Upvotes: 1