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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use of grep with pattern matching file...

Status
Not open for further replies.

arunrr

Programmer
Oct 2, 2009
103
US
Hello...

examples of the var TITLE...
TITLE="Stevens Institute of Technology"
TITLE="The Middlesex Academy of Science"
TITLE="University of Alabama"

Contents of file a.list...
Institute
Academy
College
School
University

Contents of file b.list...
N001 Institute
N002 Academy
N003 College
N004 School
N004 University

in the command...
echo $TITLE | grep -f a.list

can I use file 'b.list' instead of 'a.list' by some how directing it to match the 2nd field in the file for the pattern?

Thanks in advance...

Thanks
 
Hi

Either remove the first field :
Code:
echo "$TITLE" | grep "$( cut -d ' ' -f 2- b.list )"
Or mark the first field as optional :
Code:
echo $TITLE | grep "$( sed 's/\w\+./\\(&\\)\\?/' b.list )"
Tested with GNU [tt]grep[/tt].

Feherke.
 
Thanks again for your assistance...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top