How to from grep command from a file which contains matching words?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to from grep command from a file which contains matching words?
# 1  
Old 07-25-2008
How to from grep command from a file which contains matching words?

Hi all

I have a file with below content (content is variable whenever new product is launched). I need form a grep command like this
egrep "Unknown product|Invalid symboland so on"
How to do it using a script?

Unknown product
Invalid symbol
No ILX exch found
exceeds maximum size
AFX Industry Code INT not found
time conversion error
DJ_Parser_Service::handle_not_found
Duplicate Key so rejecting
# 2  
Old 07-25-2008
Code:
fgrep -f stringsfile targetfile

# 3  
Old 07-25-2008
grep command

Hi...

I have this script below :

$ORACLE_HOME/bin/sqlplus "/as sysdba" @/ek_ora/script/rman_error.sh > rman_error.txt

more rman_error.txt | grep -i "FAILED" >> /ek_ora/script/rman_error.tmp
if [ ! -s "/ek_ora/script/rman_error.tmp" ]
then
echo "No error found."
else
echo "Sending mail."
mailx -r oraadm@jupp.gov.my -c encass@nc.com.my -s "RMAN Error" technical@precisionportal.com.my\
< /ek_ora/script/rman_error.tmp
fi

==================================

Based on that script it will grep "FAILED" only. If identified, the script will email to me...if else, it wont send any email..

My question is, in the file rman_error.txt, sometimes there will be another value i need to grep, i need to grep ERRORS and WARNING as well, so how to do this ???
# 4  
Old 07-25-2008
If the file FAILURES.txt contains the things you want to grep for, then

Code:
fgrep -f FAILURES.txt rman_error.txt >> /ek_ora/script/rman_error.tmp

You could probably improve your script by avoiding the use of temporary files and using a pipeline instead.

Code:
sqlpus @stuff | fgrep -if FAILURES.txt | mailx -r whatever

That's just a proof of concept; it will send a message even when there are no errors.
# 5  
Old 07-29-2008
Thanks era..It works the way I wanted
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep multiple words in a file with help of fixed string switch

I have multiple strings in a file which have special character $, when i search strings by ignoring $ with \ using single quotes it returns empty results. My search strings are set char_1($lock) and set new_char_clear_3($unlock) I tried searching with but it returns empty results.However... (3 Replies)
Discussion started by: g_eashwar
3 Replies

2. UNIX for Beginners Questions & Answers

How to replace matching words defined in one file on another file?

I have file1 and file2 as shown below, file1: ((org14/1-131541:0.11535,((org29/1-131541:0.00055,org7/1-131541:0.00055)1.000:0.10112,((org17/1-131541:0.07344,(org23/1-131541:0.07426,((org10/1-131541:0.00201,org22/1-131541:0.00243)1.000:0.02451, file2: org14=india org29=america... (5 Replies)
Discussion started by: dineshkumarsrk
5 Replies

3. Shell Programming and Scripting

How to grep a log file for words listed in separate text file?

Hello, I want to grep a log ("server.log") for words in a separate file ("white-list.txt") and generate a separate log file containing each line that uses a word from the "white-list.txt" file. Putting that in bullet points: Search through "server.log" for lines that contain any word... (15 Replies)
Discussion started by: nbsparks
15 Replies

4. Shell Programming and Scripting

Understanding pattern matching used in a grep command

I have the following code. I want to remove the --sort=num/num/... and am using grep to exclude it as shown below: I have a bit of problem figuring out the use of - at the front echo "--sort=4/5/6" | grep -ivE '-((sort|group)=+/+(/+)*)$' Now suppose I want to remove --quiet I can... (7 Replies)
Discussion started by: kristinu
7 Replies

5. Shell Programming and Scripting

grep for words in file

Hi Please can you help me on this: How to grep for multiple words in a file, BUT for every word found output it to a new line. regards FR (8 Replies)
Discussion started by: fretagi
8 Replies

6. Shell Programming and Scripting

Grep multiple words in a single file

Hello All, I'm a newbie/rookie in Shell scipting. I've done oracle export of a table using Export utility. When I do export, it generates 2 files. 1> .dmp file 2> .dmp.log file. In .dmp.log file I have to search for a sentence which goes like '0 records have been inserted' and then... (2 Replies)
Discussion started by: samfisher
2 Replies

7. Shell Programming and Scripting

grep words from output file

Hi, By using shell scripit i have save output in one file. I want to grep two words named CLUSTER and CLUSQMGR from that output file. How to grep that. output file would be having below words TYPE(QCLUSTER) ALTDATE(2010-05-17) CLUSTER(QS.CL.MFT1) ... (5 Replies)
Discussion started by: darling
5 Replies

8. Shell Programming and Scripting

recursively Grep particular words among lines from a file

dear experts, Could you please help me to write a command/script to find follwing: from the log file i want to grep "resCode89270200100001552311" after that only "<resultCode>40614</resultCode>" it will be like that: resCode89270200100001552311 <resultCode>40614</resultCode> ... (7 Replies)
Discussion started by: thepurple
7 Replies

9. Shell Programming and Scripting

Usage of grep command to extract only the words.

Dear Folks, I am a newbee to UNIX. I want to extract the SQLSTATE from a log file. For example the log file content is SQL0010N The string constant beginning with "' from table1 a, table 2" does not have an ending string delimiter. SQLSTATE=42603 when I give the the command as ... (4 Replies)
Discussion started by: dinesh1985
4 Replies

10. Programming

getting file words as pattern matching

Sir, I want to check for the repation of a user address in a file i used || as my delimiter and want to check repetaip0n of the address that is mailid and then i have to use IMAP and all. How can i do this... I am in linux ...and my file is linux file. ... (5 Replies)
Discussion started by: arunkumar_mca
5 Replies
Login or Register to Ask a Question