grep remove "no such file or directory"
Hello, I'm executing the following command using cygwin : $ find . | xargs grep -v "No such file or directory" | grep "StateRB" grep: ./Tiger/codebase/netmarkets/jsp/ext/eurocopter/tiger/change/.svn/text-base/Copy: No such file or directory grep: of: No such file or directory grep: createLink.jsp.svn-base: No such file or directory grep: ./Tiger/codebase/netmarkets/jsp/ext/eurocopter/tiger/change/.svn/text-base/Copy: No such file or directory grep: of: No such file or directory grep: relatedECP.jsp.svn-base: No such file or directory grep: ./Tiger/codebase/netmarkets/jsp/ext/eurocopter/tiger/change/Copy: No such file or directory grep: of: No such file or directory grep: createLink.jsp: No such file or directory grep: ./Tiger/codebase/netmarkets/jsp/ext/eurocopter/tiger/change/Copy: No such file or directory grep: of: No such file or directory I would like not to display the "No such file or directory" output. Can anyone help me ? Cheers, Christophe -- View this message in context: http://www.nabble.com/grep-remove-%22no-such-file-or-directory%22-tp23405434p23405434.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
Re: grep remove "no such file or directory"
On 05/06/2009 02:14 PM, cseguino wrote: Hello, I'm executing the following command using cygwin : $ find . | xargs grep -v "No such file or directory" | grep "StateRB" grep: ./Tiger/codebase/netmarkets/jsp/ext/eurocopter/tiger/change/.svn/text-base/Copy: No such file or directory grep: of: No such file or directory grep: createLink.jsp.svn-base: No such file or directory grep: ./Tiger/codebase/netmarkets/jsp/ext/eurocopter/tiger/change/.svn/text-base/Copy: No such file or directory grep: of: No such file or directory grep: relatedECP.jsp.svn-base: No such file or directory grep: ./Tiger/codebase/netmarkets/jsp/ext/eurocopter/tiger/change/Copy: No such file or directory grep: of: No such file or directory grep: createLink.jsp: No such file or directory grep: ./Tiger/codebase/netmarkets/jsp/ext/eurocopter/tiger/change/Copy: No such file or directory grep: of: No such file or directory I would like not to display the "No such file or directory" output. Can anyone help me ? Cheers, Christophe This message is error message and error messages are sent to stderr. Usualy stderr are same as stdout. But you can redirect stderr with `2>'. find . 2>/dev/null This will not display any error messages from `find .' RR
Re: grep remove "no such file or directory"
On Wednesday 06 May 2009 08:14:03 cseguino wrote: > $ find . | xargs grep -v "No such file or directory" | grep "StateRB" > grep: > ./Tiger/codebase/netmarkets/jsp/ext/eurocopter/tiger/change/.svn/text-base/ >Copy: No such file or directory > grep: of: No such file or directory > grep: createLink.jsp.svn-base: No such file or directory you arent handling files with whitespace properly. use "-print0" with find and "-0" with xargs. -mike signature.asc Description: This is a digitally signed message part.
Re: grep remove "no such file or directory"
On Wednesday 06 May 2009 10:03:51 Roman Rakus wrote: > On 05/06/2009 02:14 PM, cseguino wrote: > > $ find . | xargs grep -v "No such file or directory" | grep > > "StateRB" grep: > > ./Tiger/codebase/netmarkets/jsp/ext/eurocopter/tiger/change/.svn/text-bas > >e/Copy: No such file or directory > > > > I would like not to display the "No such file or directory" output. Can > > anyone help me ? > > This message is error message and error messages are sent to stderr. > Usualy stderr are same as stdout. But you can redirect stderr with `2>'. > find . 2>/dev/null > This will not display any error messages from `find .' the error message is coming from `grep`, not `find`, and the former has a simple option to suppress errors: -s -mike signature.asc Description: This is a digitally signed message part.
Re: grep remove "no such file or directory"
On Wed, May 06, 2009 at 04:03:51PM +0200, Roman Rakus wrote: > On 05/06/2009 02:14 PM, cseguino wrote: > > $ find . | xargs grep -v "No such file or directory" | grep "StateRB" > > grep: > >./Tiger/codebase/netmarkets/jsp/ext/eurocopter/tiger/change/.svn/text-base/Copy: > >No such file or directory > > grep: of: No such file or directory [...] There are several problems with your command. What you have actually written here is "Traverse the list of all the files and directories underneath this point, opening each file and looking for all the lines that do not contain the string 'No such file or directory', and out of all those lines, look for ones that contain the string 'StateRB'." But that won't actually work as written because xargs splits your filenames on whitespace (and quotes, if Cygwin allows you to have filenames with quotes in them). This is why you got the result you got -- the "of" being treated as a separate file by xargs, instead of ".../text-base/Copy of..." being a single file. > >I would like not to display the "No such file or directory" output. Can > >anyone help me ? It's not clear what you actually DO want. > This message is error message and error messages are sent to stderr. > Usualy stderr are same as stdout. But you can redirect stderr with `2>'. > find . 2>/dev/null > This will not display any error messages from `find .' As Ramon points out, if what you're actually trying to do isn't "open up each file and look for lines not containing the string 'No such file or directory'" but rather "if find encounters an error opening a directory, don't show me find's errors", then you want this instead: find . 2>/dev/null But it's not at all clear to me where the "StateRB" part applies. If your actual problem is "Find all the files containing the string StateRB, and suppress all error messages", then use this: find . -type f -exec grep -l StateRB {} \; 2>/dev/null Or if your grep supports it: grep -l -r StateRB . 2>/dev/null (grep -r is not a standard feature, so you can't assume it will work; but it works on GNU find, which I suspect is what Cygwin has.)
Re: grep remove "no such file or directory"
Greg Wooledge writes: > If your actual problem is "Find all the files containing the string > StateRB, and suppress all error messages", then use this: > > find . -type f -exec grep -l StateRB {} \; 2>/dev/null Or with a recent version of find (also POSIX): $ find . -type f -exec grep -l StateRB {} + 2>/dev/null which has the advantage of starting less grep jobs. Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
best indirect assign of scalar and array variables
What's the best way to update a variable indirectly, e.g. when its name is passed to an update function? Since I wrote the functions below some time ago and I've wondered whether there might be a better way. It would be nice if indirect parameter assignment was as easy as indirect parameter access, i.e. if {!name} could be used on the lhs. Values/elements with embedded whitespace must not be broken. Here are the convenience functions I use now: # simple_set VARIABLE_NAME VALUE... # sets the named variable to the specified value/list simple_set() { local -r name="${1}" ; shift eval "${name}='${*}'" } #simple_array ARRAY_NAME ELEMENT... # sets named variable to an array of the specified elements simple_array() { local -r vals=( "${@:2}" ) eval "$1=(\"\${va...@]}\")" } Now that BASH supports associative arrays I will need to write something to set those indirectly too. Thanks for your suggestions, _Greg J. Greg Davidson