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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep help flood Shell Programming and Scripting 3 06-05-2008 10:14 PM
Grep Aejaz UNIX for Advanced & Expert Users 3 04-30-2008 04:10 AM
grep dineshr85 Shell Programming and Scripting 1 10-10-2007 01:52 AM
how to exclude the GREP command from GREP yamsin789 UNIX for Advanced & Expert Users 2 10-04-2007 11:59 PM
Make grep -c display like grep -n? Jerrad Shell Programming and Scripting 2 08-24-2006 09:20 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-08-2006
Registered User
 

Join Date: Jun 2006
Posts: 8
grep and ksh

Hi,

Can someone please help me with the below query,

I have a list of country codes in an array 'tempCountry'. I need to search for the occurence of the string "[countryCode]" in a log.
eg: "grep '\[DE]\' myLog" works fine. However when i do the following in a ksh script, it doesn't work as intended

Code:
tempCountry=${countries[${count}]}

if [[ $(grep -c '\[${tempCountry}\]' ${MY_LOG}) -gt 0 ]] ; then
   echo "Found  ${tempCountry} in log"
else
   echo "Not Found  ${tempCountry} in log"
I get a Not Found response for all the countries which is not true. I am assuming that something is wrong with the way the if loop is interpreted by the grep command/ksh.

TIA
Reply With Quote
Forum Sponsor
  #2  
Old 06-08-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
change:
Code:
grep -c '\[${tempCountry}\]'
to:
Code:
grep -c "\[${tempCountry}\]"
The single quotes are causing every thing within the quotes to be litterally interpreted.

You can see this happening by placing "set -x" before if statement and "set +x" after the last line of the if statement.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:28 PM.


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