Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help using grep -f 1

Status
Not open for further replies.

johngiggs

Technical User
Oct 30, 2002
492
US
When I enter in a series of strings in a pattern file to be used by grep -f, is there any way to specify that it return the results in the order specified in the pattern file rather than as it finds them?

I.E. I have the pattern file that contains something like the following:

backup7
backup2
backup4
backup13
backup1
...

And the grep -f returns the following:

backup13
backup4
backup7
backup1
...

How can I make it read the file and grep for the results in the order specified in the pattern file?

Any help would be greatly appreciated.

Thanks,

John
 
Instead of
Code:
 grep -f pattern.lst ...
try something like this:
Code:
while read PAT
do
  grep "$PAT" ...
done<pattern.lst

Hope This Help
PH.
 
PHV,

Thank you for your help. I had thought of using that, however I thought that it would be very CPU intensive. I ended up using another solution and incorporating your suggestion above.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top