grep and ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep and ksh
# 1  
Old 06-08-2006
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
# 2  
Old 06-08-2006
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep for process in a ksh script

Hi I'm trying to catch a particular process (XYZ) running using a ksh script. Like So.. VarPS=`ps -ef |grep XYZ |grep -v grep` However this seems to find the process of the script itself - not the process 'XYZ' Asked in Error - I found my own typo... thanks anyway Skrynesaver (1 Reply)
Discussion started by: Mudshark
1 Replies

2. Shell Programming and Scripting

Ksh: Send a mail in case grep finds something

I want to search a file if it contains special strings and if yes, the records found should be mailed. I can either do it with a temporary file: /usr/bin/grep somestring somefile > /tmp/tempfile && /usr/bin/mail -s "Found something" email@mycomp.com < /tmp/tempfile... or by running the grep... (10 Replies)
Discussion started by: Cochise
10 Replies

3. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies

4. UNIX for Dummies Questions & Answers

Help with grep & count in ksh

Hello, I have input file with queue names No.esprd.Queue|No.esdev.Queue|||n|120|No_User||No_User| No.esdev.Queue|No.esdev.Queue|||n|120|No_User||No_User| I have to check if the input file contains word "esprd" and the number of times it occurs. I will have to do further... (22 Replies)
Discussion started by: Green_Star
22 Replies

5. Shell Programming and Scripting

ksh script to process grep output

Hi, I would like to know how can i pipe the following output of grep into a predefined output format This is the output of the grep command grep record *.txt | sort -r 2010-04-28-11-12-21.txt:C The user has created a record 2010-04-29-10-18-41.txt:U The user has updated a record... (8 Replies)
Discussion started by: alienated
8 Replies

6. Shell Programming and Scripting

Grep a number from a line in ksh

In file.name, I have a line that reads $IDIR/imgen -usemonths -dropcheck -monitor -sizelimit 80000000 -interval 120 -volcal HSI How can I get the size limit, i.e. 80000000 out and pass it to a variable called SIZE? Thanks. I tried echo "grep sizelimit file.name" | sed -n -e... (3 Replies)
Discussion started by: rodluo
3 Replies

7. Shell Programming and Scripting

grep in ksh

I am running on SunOS, KSH For my script , I want to test if a file contain 'PLS' OR 'ORA' OR 'ERROR' Can we do it in one line using grep ??? currently i am using something like below. ERROR_CHK () { ERR_DATA="$ABC" if $(echo "$ABC" | grep ERROR) ;then echo "Failed: Can't... (4 Replies)
Discussion started by: Amresh Dubey
4 Replies

8. Shell Programming and Scripting

grep command with combined variables in Ksh

Hi, I'd like to grep two variables that are seperated with one space in ksh. var1="Feb" var2="09" I tried to grep "$var1 ""$var2" /usr/file It turn into grep Feb 09 /usr/file when it runs. I got error. Can some one help me with this one? Thanks a lot for your help! (4 Replies)
Discussion started by: cin2000
4 Replies

9. Shell Programming and Scripting

grep within ksh program

Hi, is there problem with grep command when using ksh? I had the below command: /usr/bin/grep \""$Mon $NewDD\"" /tmp/timemanager/intlog.$$ >> /tmp/timemanager/log.$$ 2>/dev/null when I run ksh in debug mode, this command can not grep anything even the data is in the file. + /usr/bin/grep... (3 Replies)
Discussion started by: cin2000
3 Replies

10. Shell Programming and Scripting

script ksh/awk/grep

How can I extract the 9th line of a text file. thanks vm.:confused: (2 Replies)
Discussion started by: hoang
2 Replies
Login or Register to Ask a Question