LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   shell script having multiple grep statements-I want input file to be read only once (http://www.linuxquestions.org/questions/linux-newbie-8/shell-script-having-multiple-grep-statements-i-want-input-file-to-be-read-only-once-665504/)

mukta9003 08-26-2008 08:21 AM

shell script having multiple grep statements-I want input file to be read only once
 
Hi,
My shell script is having multiple grep statements for extracing various things from file. For every grep its going through the input file .
I want a script(shell or awk)such that it will go through the input file only once .
For each line it will check if any regular expression is matching and go ahead. I will have a separate file for storing set of regular expressions and another file having input data.
Pls help me.
Thanks in advance.

----My code looks something like this---------


echo " "
echo "Email addresses-----";
echo " "
egrep -o "###some regex for email###" $filename
#=======================================================================

echo "Web links-----";
echo " "
egrep "#### some regex for web links###" $filename |grep -v "\w*@\w"
echo " "
exit 0

theYinYeti 08-26-2008 09:05 AM

Did you read the grep manual?
Code:

      -f FILE, --file=FILE
              Obtain patterns from FILE, one per line.  The empty file contains zero patterns,
              and therefore matches nothing.

Yves.

mukta9003 08-27-2008 12:22 AM

thaks for support..

i tried with /bin/egrep -f <pattern_file> <input_data_file>
now its working i guess... but still i am not getting how to differentiate between the outputs.All regex are stored in pattern_file .I want output like this:
regex1 output :
regex2 output :

Tinkster 08-27-2008 12:48 AM

So what are you doing differently from the command-line
in the script?

Mr. C. 08-27-2008 12:58 AM

Grep is the wrong tool for this. If you want to print out the RE that matched, use awk or perl, or even a bash script.

To me, this seems like a homework assignment, so spend some time working out some solutions, and ask when you need assistance.


All times are GMT -5. The time now is 11:16 PM.