Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-26-2008, 09:21 AM   #1
LQ Newbie
Registered: Aug 2008
Posts: 2

Rep: Reputation: 0
Exclamation shell script having multiple grep statements-I want input file to be read only once

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
Old 08-26-2008, 10:05 AM   #2
Senior Member
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
Did you read the grep manual?
       -f FILE, --file=FILE
              Obtain patterns from FILE, one per line.  The empty file contains zero patterns,
              and therefore matches nothing.
Old 08-27-2008, 01:22 AM   #3
LQ Newbie
Registered: Aug 2008
Posts: 2

Original Poster
Rep: Reputation: 0
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 :

Last edited by mukta9003; 08-27-2008 at 01:54 AM.
Old 08-27-2008, 01:48 AM   #4
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,049
Blog Entries: 11

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
So what are you doing differently from the command-line
in the script?
Old 08-27-2008, 01:58 AM   #5
Mr. C.
Senior Member
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Shell] Read a File from script yussef Programming 4 08-19-2008 05:26 AM
shell script to read input from csv ip addresses? kr0m3 Programming 3 07-21-2007 09:51 AM
How to read data from file to use in shell script? ozymandias Linux - Newbie 7 10-27-2006 02:19 PM
help on shell script as a wrapper to launch default programs according to input file daveiro Programming 2 11-24-2005 05:20 PM
if statements and case statements not working in bourne shell script mparkhurs Programming 3 06-12-2004 03:41 AM

All times are GMT -5. The time now is 05:04 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration