File grep quick query


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers File grep quick query
# 1  
Old 11-09-2013
RedHat File grep quick query

Hi Experts,

I need some suggestion on file grep.

I am trying to find multiple pattern with the file grep as below

Code:
grep "2013" trace.log | grep -f pattern.cfg -i  > $LOG
if [ -s $LOG ] ; then
 mail -s "Exception" "sample@abc.com" < $LOG
fi

Is it possible to obtain what pattern I got in the results? Is there any way to get the what pattern I got in the results ?

Thanks
# 2  
Old 11-09-2013
Not using a single grep.

You could use one grep for each line in pattern.cfg.

You could use something iike awk to read pattern.cfg and match each of the basic regular expressions against the lines in trace.log (note, however, that awk uses extended regular expressions instead of BREs) and print both the matched line and the RE that matched it.

Without knowing more about what your data looks like (both pattern.cfg and trace.log) and what output you want, we can only make wild guesses about what you're trying to do.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 11-11-2013
Please find the details
Code:
$cat pattern.cfg
OutOfMemory
Staleconnection

Pattern varies per server and it may increase or decrease.
So shall i modify like below, Is there any other smarter way to identify the same
Code:
grep "2013" trace.log | grep -f pattern.cfg -i  > $LOG.TMP
if [ -s $LOG ] ; then
 echo "Error Found for following exception" > pattern.stg
 while read string
 do
 pattern=$(grep "$string" $LOG.TMP)
 echo "pattern" >> pattern.stg
 done
 cat pattern.stg > $LOG
 mail -s "Exception" "sample@abc.com" < $LOG
fi

# 4  
Old 11-11-2013
As I said before: "Without knowing more about what your data looks like (both pattern.cfg and trace.log) and what output you want, we can only make wild guesses about what you're trying to do." You have now shown us a sample pattern.cfg file. Please show us a sample trace.log file and the output that you want to be produced as a result of processing those two sample input files.

Note that the:
Code:
 while read string
 do
 pattern=$(grep "$string" $LOG.TMP)
 echo "pattern" >> pattern.stg
 done

in your script does not specify a file from which "string"s will be read. So this script will wait for you to type in strings (without prompts) while it is running. Did you intend to redirect input to this loop from pattern.cfg? (Once you show us a complete set of input files and your desired output, this point might not matter; but as it currently stands, we just don't know what output you are trying to produce.)
This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 11-11-2013
It was missing in the "done" it should be

Code:
done<pattern.cfg

But I am unable to post the traces logs show here. But still we can consider this way for my experiment.
# 6  
Old 11-11-2013
You don't have to post REAL data, just representative data. We'd be happy to help you if you would just make up a representative sample of the inputs and output with sensitive data (names, phone numbers, account numbers, etc.) replaced by made up replacements that use the same data formats.

You're already using sample@abc.com as the e-mail address to receive your messages. I assume that isn't the real intended destination. Do the same thing for the rest of your sample data.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Quick help on grep -w please

Hello Experts, Here is my problem.. cat abc.txt 1,"nathan available" 2,"MW nathan available" 3,"HW nathan available" How can i grep for "nathan available" alone. I tried grep -w "nathan available" Problem is that the pattern is enclosed in Quotes " ". I know we can do grep... (2 Replies)
Discussion started by: sathyaonnuix
2 Replies

2. UNIX for Dummies Questions & Answers

[Quick question]Problem with execl and GREP

Guys, I have the following code #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/wait.h> #include <unistd.h> void read2(); main(int argc, char** argv) { int pid,status; pid=fork(); if ( pid == 0 ) { read2(argv,... (4 Replies)
Discussion started by: pfpietro
4 Replies

3. Shell Programming and Scripting

A quick query

Hello All, i am facing an issue and could not understand the possible reason... When the following command is executed from command line (from # prompt) the output is as desired but executing the same from a shell script, the result is an error. It is important for the command to execute in... (7 Replies)
Discussion started by: EmbedUX
7 Replies

4. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

5. UNIX Desktop Questions & Answers

ls grep query

Hi please can someone help me with a query? The following command is executed: $ ls abc def hij You execute the command: ls | grep f*. Which files will be displayed and why? thanks (13 Replies)
Discussion started by: tmn0004676
13 Replies

6. Shell Programming and Scripting

Grep query

As part of my never-ending nagios automation project I am need to implement the following run line into a loop; -bash-3.00$ grep ${feed} /usr/local/feed/service/clients/*/bin/* | awk -F/ '{print "To restart: /"$2"/"$3"/"$4"/"$5"/"$6"/"$7"/"$8"/"$9}' Which prints to screen; To restart:... (3 Replies)
Discussion started by: JayC89
3 Replies

7. Shell Programming and Scripting

Query regarding grep

In what cases the following command ignores lines in input file: $ grep -c "^" inputfile (1 Reply)
Discussion started by: amicon007
1 Replies

8. Shell Programming and Scripting

Quick question on grep: grabbing lines above and below

Just a quick question on grep/egrep. I am writing a shell script that is looking for certain strings in a text file. It works well and gets exactly what I need. However, the way the program writes to the text file, it puts the timestamp in a line above the string I am looking for and the path... (3 Replies)
Discussion started by: thecoffeeguy
3 Replies

9. UNIX for Dummies Questions & Answers

Quick Grep question

Is it possible to grep for two words at once? I want to grep for the words SEVERE or FATAL. Thanks. (1 Reply)
Discussion started by: ssmiths001
1 Replies
Login or Register to Ask a Question