Grep Without Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow grep error no such file or directory the company Business Learn more about hiring developers or posting ads with us Stack grep suppress permission denied Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of
Grep No Such File Or Directory Problem
4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Avoid grep returning error when input doesn't match up vote 32 down vote favorite 4 I want
Grep No Such File Or Directory Bash
to write in a bash script a piece of code that checks if a program is already running. I have the following in order to search whether bar is running foo=`ps -ef | grep bar | grep -v grep` The grep -v grep part is to ensure that the "grep bar" is not taken into account in ps results When bar isn't running, foo is correctly empty. But my problem lies in grep no such file or directory recursive the fact tha the script has set -e which is a flag to terminate the script if some command returns an error. It turns out that when bar isn't running, "grep -v grep" doesn't match with anything and grep returns an error. I tried using -q or -s but to no avail. Is there any solution to that? Thx bash grep share|improve this question asked Jul 1 '11 at 16:13 George Kastrinis 2,62621837 add a comment| 4 Answers 4 active oldest votes up vote 34 down vote accepted Sure: ps -ef | grep bar | { grep -v grep || true; } Or even: ps -ef | grep bar | grep -v grep | cat share|improve this answer answered Jul 1 '11 at 16:17 Sean 19.9k14676 Great! That fixed it. Thx :) –George Kastrinis Jul 1 '11 at 16:20 2 The first is better in that it also works with "-o pipefail", another good fail-fast setting for bash similar to "-e". –Jaka JanĨar Jul 13 at 7:49 add a comment| up vote 13 down vote A good trick to avoid grep -v grep is this: ps -ef | grep '[b]ar' That regular expression only matches the string "bar". However in the ps output, the string "bar" does not appear with t
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers
Grep Ignore No Such File Or Directory
or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix grep no such file or directory shell script & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes grep exit code always 0 a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top How can I suppress output from grep, so that it only returns the exit http://stackoverflow.com/questions/6550484/avoid-grep-returning-error-when-input-doesnt-match status? up vote 19 down vote favorite 2 I have the grep command. I'm searching for a keyword from a file, but I don't want to display the match. I just want to know the exit status of the grep. shell-script scripting grep share|improve this question edited Dec 11 '13 at 3:56 phunehehe 10.4k1363127 asked Dec 11 '13 at 1:38 jackass27 98114 add a comment| 4 Answers 4 active oldest votes up vote 24 down vote accepted Any POSIX compliant version of http://unix.stackexchange.com/questions/104641/how-can-i-suppress-output-from-grep-so-that-it-only-returns-the-exit-status grep has the switch -q for quiet: -q Quiet. Nothing shall be written to the standard output, regardless of matching lines. Exit with zero status if an input line is selected. In GNU grep (and possibly others) you can use long-option synonyms as well: -q, --quiet, --silent suppress all normal output Example String exists: $ echo "here" | grep -q "here" $ echo $? 0 String doesn't exist: $ echo "here" | grep -q "not here" $ echo $? 1 share|improve this answer edited Oct 11 at 9:22 Wildcard 9,59431560 answered Dec 11 '13 at 2:00 slm♦ 165k40305474 add a comment| up vote 4 down vote Just redirect output of grep to /dev/null: grep sample test.txt > /dev/null echo $? share|improve this answer edited Dec 11 '13 at 5:52 answered Dec 11 '13 at 1:45 cuonglm 71.8k13114199 This will fail to echo $? if grep returns a non-zero exit code. –WinnieNicklaus Dec 11 '13 at 5:00 Thanks, fixed it. –cuonglm Dec 11 '13 at 5:52 add a comment| up vote 0 down vote You simply need to combine grep -q
Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here. Search Forums Show Threads Show Posts Tag Search Advanced Search Unanswered Threads Find All Thanked Posts Go to http://www.unix.com/shell-programming-and-scripting/104999-how-avoid-grep-warning-messages.html Page... linux operating commands and unix operating commands How to avoid grep warning messages http://superuser.com/questions/382333/ubuntu-grep-find-etc-permission-denied-and-no-such-file-or-directory-outpu Shell Programming and Scripting Tags grep warning Thread Tools Search this Thread Display Modes #1 03-18-2009 shellscripter Registered User Join Date: Oct 2008 Last Activity: 1 October 2010, 1:34 AM EDT Location: chennai Posts: 17 Thanks: 0 Thanked 0 Times in 0 Posts How to avoid grep warning messages Hi All, When no such i try to grep for a patern in an directory, I am getting warning like "No such file or directory". Anyway script is working as expected. but i need to avoid this warning message. Pass="`find . -type f | xargs grep 'test result - pass' | wc -l`" grep: ./results/6052278-1-717520-HFR_QFTS_ALL.__taskid2.isis_test.Beginning: No such file or directory grep: ISIS: No such file or directory grep: config: No such file or directory grep: load: No such file or directory grep: no such file ./results/6052278-1-717520-HFR_QFTS_ALL.__taskid2.isis_test.Beginning: No such file or directory grep: interface%2Fbasic: No such file or directory grep: pings%2Ftraceroute%2Fcontroller: No such file or directory grep: check: No such file or directory Thanks, Parkkavan Remove advertisements Sponsored Links shellscripter View Public Profile Find all posts by shellscripter #2 03-18-2009 Franklin52 Moderator Join Date: Feb 2007 Last Activity: 12 October 2016, 6:23 PM EDT Location: The Netherlands Posts: 7,746 Thanks: 139 Thanked 558 Times in 520 Posts Redirect the output of stderr to /dev/null: Code: find . -type f | xargs grep 'test result - pass' 2>/dev/null | wc -l Remove advertisements Sponsored Links Franklin52 View Public Profile Find all posts by Franklin52 #3 03-18-2009 shellscripter Registered User Join Date: Oct 2008 Last Activity: 1 October 2010, 1:34 AM EDT Location: chennai Posts: 17 Thanks: 0 Thanked 0 Times in 0 Posts Thanks Franklin. It works fine.. Can you tellme "2" mean in 2>/dev/null. Thanks, Parkkavan shellscripter View Public Profile Find all posts by shellscripter #4 03-18-2009 wireonfire Registered User Join Date: Oct 2008 Last Activity: 9 July 2009, 3:13 PM EDT Posts: 19 Thanks: 0 Thanked 0 Times in 0 Posts 2 by default is the file pointer for the error messages, 1 is that for stand output. Both go to screen by default. In this case you redirect error to /dev/n
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Super User Questions Tags Users Badges Unanswered Ask Question _ Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Ubuntu grep, find etc: “Permission denied” and “No such file or directory” output up vote 13 down vote favorite When I grep or find something I always get annoyed by the "Permission denied" and "No such file or directory" notice, smth like that: johndoe@johndoe-desktop:/$ grep -rnP 'YII_CORE_PATH' ./ | grep -v .svn grep: ./lib/ufw/user6.rules: Permission denied grep: ./lib/ufw/user.rules: Permission denied grep: ./lib/init/rw/udev/watch/27: No such file or directory grep: ./lib/init/rw/udev/watch/26: No such file or directory grep: ./lib/init/rw/udev/watch/25: No such file or directory How can I avoid it and make it show only relevant data, i.e. something that I really look for? linux bash ubuntu find grep share|improve this question asked Jan 24 '12 at 17:08 Zapadlo 166126 migrated from stackoverflow.com Jan 25 '12 at 18:00 This question came from our site for professional and enthusiast programmers. Related: stackoverflow.com/a/25234419/54964 –Masi Jul 4 at 15:46 add a comment| 4 Answers 4 active oldest votes up vote 18 down vote accepted with grep you could specifiy the -s flag which does pretty much what @ortang said -s, --no-messages Suppress error messages about nonexistent or unreadable files. Portability note: unlike GNU grep, 7th Edition Unix grep did not conform to POSIX, because it lacked -q and its -s option behaved like GNU grep's -q option. USG-style grep also lacked -q but its -s option behaved like GNU grep. Portable shell scripts should avoid both -q and -s and should redirect standard and error output to /dev/null instead. with find as far as I know @ortangs answer is the best. something like find / -name "myfile" -type f -print 2>/dev/null share|improve this answer answered Jan 24 '12 at 18:51 matchew 3661211 add a comment| up vote 6 down vote Try redirecting stderr to /dev/null. johndoe@johndoe-desktop:/$ grep -rnP 'YII_CORE_PATH' ./ 2> /dev/null | grep -v .svn share|improve this answer answered Jan 24 '12 at 17:54 ortang 33929 add a com