|
From: | Eric Backus |
Subject: | Re: grep -R "include" *.c --- not working |
Date: | Mon, 4 Oct 2004 10:56:38 -0700 |
Hello,> find . -name '*.c' -print0 | xargs -r0 grep include /dev/null >> This ensures that grep always preceeds the match with a filename, even > if> there's only one file found.since you already use two GNU-specific features (-r and -0 in xargs), you could as well adopt another one: find . -name '*.c' -print0 | xargs -r0 grep -H include or find . -name '*.c' -print0 | xargs -r0 grep --with-filename include The solution with /dev/null is a kludge.
Agreed, the /dev/null is a kludge. But it works, and it's portable to essentially any unix-like system. A person has to learn either /dev/null or -H about grep, to make it work reliably in this situation. The /dev/null is more portable, so learn that one. No point in learning both, save that room in your brain for something more essential, like another emacs keybinding or something...
(By comparison, there is no way that I know of, even with kludges, to do the equivalent of -r or -0. To be honest, I'm not convinced that the -r is even necessary when running grep like this.)
-- Eric Backus
[Prev in Thread] | Current Thread | [Next in Thread] |