If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > grep for count of a word

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-08-07, 18:38
saccskiz saccskiz is offline
Registered User
 
Join Date: Feb 2004
Posts: 143
grep for count of a word

In a unix shell script(say do.ksh), I want to read a file called load_errors.log and count the word ORA- for the number of occurances.
If the occurance is more than 50, then I would like the unix shell script to exit with a message "ORA- found more than 50 times"

How can this be done ? Thanks
Reply With Quote
  #2 (permalink)  
Old 08-09-07, 03:09
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
The following script assume that there is no more than one error per line:

Code:
if (( $(grep -c 'ORA-' ) > 50 ))
then
   echo "ORA- found more than 50 times"
fi
__________________
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 08-09-07, 06:42
saccskiz saccskiz is offline
Registered User
 
Join Date: Feb 2004
Posts: 143
will this be fine

Thank you. But the script that I want to include these lines is supposed to grep in another file for those words.
How do I specify the other file usage ?


Will this work:

if (( $(grep -c 'ORA-' load_errors.log ) > 50 ))
then
echo "ORA- found more than 50 times"
fi
Reply With Quote
  #4 (permalink)  
Old 08-09-07, 07:09
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
This will work.
I have tested my script with stdin and forget to add the file name in my post.
__________________
Jean-Pierre.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On