Grep Not Found 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 the company Business Learn more about hiring developers
If Not Grep
or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x grep exit status Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it grep if not found only takes a minute: Sign up Print a dash if grep not found up vote 0 down vote favorite I would like this command to print a dash if grep not found (in addition to the new line already coded):
Grep If Pattern Not Found
while read vl ; do grep -w "$vl" APL_vs_HS.tab || printf "\n" ; done < 1 Thanks! Bernardo bash shell grep share|improve this question edited Dec 19 '13 at 16:56 anubhava 383k32160232 asked Dec 19 '13 at 16:52 biotech 234112 What have you tried, and what error are you getting? –Donovan Dec 19 '13 at 17:00 1 By "grep not found", do you mean that the grep command doesn't exist, or that grep doesn't find the pattern?
If Grep
I presume the latter, but the way you phrased it implies the former. –Keith Thompson Dec 19 '13 at 17:07 add a comment| 2 Answers 2 active oldest votes up vote 3 down vote accepted Why do you need to use printf? Simply use echo, then you won't need to worry about printing a newline because echo automatically outputs one. while read vl ; do grep -w "$vl" APL_vs_HS.tab || echo "-" ; done < 1 share|improve this answer answered Dec 19 '13 at 17:13 dogbane 137k42236324 add a comment| up vote 3 down vote See this, so that one would do while read vl; do grep -w "$vl" APL_vs_HS.tab || printf -- "-\n" ; done < 1 share|improve this answer answered Dec 19 '13 at 17:04 kbshimmyo 599310 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged bash shell grep or ask your own question. asked 2 years ago viewed 2169 times active 2 years ago Visit Chat Linked 151 How can I grep for a string that begins with a dash/hyphen? Related 1890Grep a file, but show several surrounding lines
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 grep error if not found User Questions Tags Users Badges Unanswered Ask Question _ Super User is a question and answer site
Bash If Grep
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 grep q answer The best answers are voted up and rise to the top How to grep to check if strings is not there in a file (in linux) and also the case of multiple strings? up vote 8 down vote favorite 1 I want http://stackoverflow.com/questions/20687308/print-a-dash-if-grep-not-found to search if "ack_enabled not defined" is not there in a particular file all_defs.txt and return something, by which i can understand that the string is not there. Can anyone tell me how to do it? Also, the second part is that, i have a a list of strings stored in a file. Each line has a multiworded string that has to be checked individually if present in another file. linux grep share|improve this question edited Sep 27 '13 at 7:40 asked Sep 27 '13 at 7:22 http://superuser.com/questions/650976/how-to-grep-to-check-if-strings-is-not-there-in-a-file-in-linux-and-also-the-c RoyOneMillion 51124 add a comment| 2 Answers 2 active oldest votes up vote 9 down vote Just check the exit code of grep. -q makes it silent, ! negates the exit code: if ! grep -q 'ack_enabled not defined' all_defs.txt ; then echo Not found. fi share|improve this answer answered Sep 27 '13 at 7:28 choroba 8,85911727 add a comment| up vote 5 down vote More vebose one-liner The following one-liner is even more verbose: grep -q 'ack_enabled not defined' all_defs.txt && echo 'string found' || echo 'string not found' share|improve this answer edited Oct 25 '15 at 19:13 answered May 9 '14 at 14:44 Serge Stroobandt 496613 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged linux grep or ask your own question. asked 3 years ago viewed 18799 times active 6 months ago Related 5How do you search for strings in a file which in turn is in an archive?2Read a file and pipe to grep0Linux Grep Multiple Log Files0How to grep multiple strings on multiple files?2How to grep a group of files within a time range?1String Search: find and grep and?0Check which string occurs first in a growing file1How to use grep on a variable or string?0grep % 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 http://unix.stackexchange.com/questions/48535/can-grep-return-true-false-or-are-there-alternative-methods more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & 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 a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The not found best answers are voted up and rise to the top Can grep return true/false or are there alternative methods up vote 40 down vote favorite 14 I'm trying to write this script for an assignment - it's only the second one I've written so bear with me. As a part of this script, I need to be able to check if the first argument given matches the first word of if not found file. If it does, exit with an error message, if it doesn't, append the arguments to the file. I understand how to write the if statement, but not how to use grep within a script. I understand that grep will look something like this grep ^$1 schemas.txt I feel like this should be much easier than I am making it. Any help appreciated. Update: I'm getting an error too many arguments on the if statement. I got rid of the space between grep-q and then got an error binary operator expected. I've been poking around at it, but I don't see what it sees. if [ grep -q ^$1 schemas.txt ] then echo "Schema already exists. Please try again" exit 1 else echo "$@" >> schemas.txt fi grep share|improve this question edited Sep 9 '15 at 8:39 don_crissti 28.7k56898 asked Sep 18 '12 at 17:33 Lauren 235159 1 Lose the […] and it'll work. Though you probably want to quote your pattern: if grep -q "^$1" schemas.txt; then … –derobert Sep 18 '12 at 19:25 one line solution using Bash's "Group Command" feature: stackoverflow.com/questions/6550484/… –Trevor Boyd Smith Sep 27 at 19:46 add a comment| 4 Answers 4 active oldest votes up vote 62 down vote accepted g