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!

grep - need to idendify which pattern in the pattern matching file

Status
Not open for further replies.

arunrr

Programmer
Oct 2, 2009
103
US
Here is my situation...

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

By using...

echo $TITLE | grep -f a.list

I need to extend this to get the line from file b.list in order to extract the Nxxx number.

Hope this is clear. Help is appreciated...
 
Hi

[tt][small][blue][ignore][offtopic][/ignore][/blue][/small][/tt]
You may continue with [tt]grep[/tt] :
Code:
echo "$TITLE" | grep [highlight]-o[/highlight] -f a.list [highlight]| grep -f - b.list[/highlight]
Tested with GNU [tt]grep[/tt].
[tt][small][blue][ignore][/offtopic][/ignore][/blue][/small][/tt]
Code:
awk -vt="$TITLE" 't~$2{print$1}' b.list
Tested with [tt]gawk[/tt] and [tt]mawk[/tt].

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top