The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
grep for pattern aemunathan Shell Programming and Scripting 12 05-08-2008 11:58 PM
How to grep this pattern?? askumarece Shell Programming and Scripting 13 02-20-2008 04:03 AM
help with grep the pattern bluemoon1 Shell Programming and Scripting 2 09-20-2007 08:27 AM
Appending to filename a string of text grep finds HLee1981 Shell Programming and Scripting 3 09-06-2005 11:44 AM
grep error message gammaman UNIX for Dummies Questions & Answers 3 07-10-2005 08:58 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 03-03-2006
Registered User
 

Join Date: Mar 2006
Posts: 2
fixing the error message when grep doesn't finds the pattern.

Hi,
I am running the below script.
---------------------------------------------------------
#!/bin/ksh
for tname in `cat tables.txt | cut -f 1` ;
do
if (test -n `grep -il "$tname" /fs/scripts/*`)

then echo ${tname} >> UsedTables.txt

else echo ${tname} >> UnUsedTables.txt

fi
done
---------------------------------------------------------
Its running fine if grep finds the pattern but when the pattern is not found its giving the following error message:

script1.ksh[5]: test: argument expected

Eventhough it throws the message but its appending the ${tname} value in the files.

Can anyone let me know how to avoid the error message when grep doesn't finds the pattern.

Thanks.
Reply With Quote
Forum Sponsor
  #2  
Old 03-03-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,683
Ygor had closed your earlier thread - script to search for the contents of a file on the grounds of violating the no-homework rule.

I will not give you any solution because its homework. But rather suggestions because you have a script that works partially.

grep has a -q option. Read the man pages to see what it does. Use the exit status which results from that option and proceed. Read man ksh to see how you can use the construct ((expression)) together with the -q option.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0