LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
Search this Thread
Old 08-26-2008, 08:21 AM   #1
mukta9003
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


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

Rep: Reputation: 61
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.
 
Old 08-27-2008, 12:22 AM   #3
mukta9003
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 12:54 AM.
 
Old 08-27-2008, 12:48 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,962
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
So what are you doing differently from the command-line
in the script?
 
Old 08-27-2008, 12: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.
 
  


Reply


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 04:26 AM
shell script to read input from csv ip addresses? kr0m3 Programming 3 07-21-2007 08:51 AM
How to read data from file to use in shell script? ozymandias Linux - Newbie 7 10-27-2006 01:19 PM
help on shell script as a wrapper to launch default programs according to input file daveiro Programming 2 11-24-2005 04:20 PM
if statements and case statements not working in bourne shell script mparkhurs Programming 3 06-12-2004 02:41 AM


All times are GMT -5. The time now is 11:33 AM.

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