The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
question about wc command in Unix thungmail Shell Programming and Scripting 3 04-22-2008 02:11 AM
Question about UNIX ioscan command Spilson HP-UX 10 11-22-2007 09:02 PM
Unix command question BMWBigD UNIX for Dummies Questions & Answers 2 06-24-2005 10:36 AM
Unix History Question: Why are filenames/dirnames case sentsitive in Unix? deckard UNIX for Dummies Questions & Answers 3 03-26-2005 01:59 PM
Question about DOS versus Unix Command? wmosley2 UNIX for Dummies Questions & Answers 1 12-09-2003 10:27 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-18-2003
wazzag wazzag is offline
Registered User
  
 

Join Date: Aug 2003
Posts: 2
Question about a unix command...

hi all,

got a question about grep, ive written a script (Bourne) and i'm using grep -i to search for a file and return the records that i'm looking for. This all works fine, but, i was wondering how i can get an error message if that word isn't in the file.
E.G.
the user enters: tree
and if tree wasn't in the file it would say:
tree not found

cheers, waz.
  #2 (permalink)  
Old 08-18-2003
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
On the command line, type the following: man grep That should be all you need to know! On the otherhand, in case that doesnt help, try grep -ic pattern files | grep :0 One thing to note, if none of your files contain the pattern, grep will not return anything.

Last edited by google; 08-18-2003 at 09:08 AM..
  #3 (permalink)  
Old 08-18-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
You can also learn this from the man page, but you can do a test to see if the grep command was successful or not by using $?

Code:
grep -qi pattern your_files ; if [ $? -eq 1 ]; then echo "not found"; fi

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0