grep in ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep in ksh
# 1  
Old 11-15-2007
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 execute procedure ${PRG_NAME} ERROR found "
return 1
elsif $(echo $"ERR_DATA"| grep ORA) then
echo "Failed: Can't execute procedure ${PRG_NAME} ORA Error found "
elsif $(echo $"ERR_DATA"| grep PLS) then
echo "Failed: Can't execute procedure ${PRG_NAME} PLS Error found"
else
echo "Info : ${PRG_NAME} done"
fi

}


I will appriciate if you can come with a more streamlined version of above function
# 2  
Old 11-15-2007
Code:
grep -e "PLS
ORA
ERROR" filelist....

# 3  
Old 11-15-2007
I did like

ERROR_CHK () {

ERR_DATA="$ABC"
if `echo "$ABC" | egrep 'PLS|ERROR|ORA'` ; then
echo "Failed: Can't execute procedure ${PRG_NAME} ERROR found "
return 1
else
echo "Info : ${PRG_NAME} done"
fi

}

but it fails with

ERROR: not found message

;; any help
# 4  
Old 11-15-2007
Quote:
Originally Posted by Amresh Dubey
any help
I thought I had just suggested something.
# 5  
Old 11-15-2007
Quote:
Originally Posted by Amresh Dubey
I did like

ERROR_CHK () {

ERR_DATA="$ABC"
if `echo "$ABC" | egrep 'PLS|ERROR|ORA'` ; then
echo "Failed: Can't execute procedure ${PRG_NAME} ERROR found "
return 1
else
echo "Info : ${PRG_NAME} done"
fi

}

but it fails with

ERROR: not found message

;; any help
Like the previous "suggestion" Smilie stated, you can check for multiple patterns with the -e option with grep, here's an example:
Code:
/usr/xpg4/bin/grep -e root -e  daemon -e sys # or something like
echo $ERR_DATA | /usr/xpg4/bin/grep -e PLS -e ERROR -e ORA 
[ $? -eq 0 ] && echo Pattern match found, oracle prob occured!

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 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 "" in a log. eg: "grep '\\' myLog" works fine. However when i do the following in a ksh script, it doesn't work as intended ... (1 Reply)
Discussion started by: psynaps3
1 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