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!

Using variables inside regular expressions 1

Status
Not open for further replies.

LustyT

Programmer
Apr 7, 2005
2
GB
I wonder if you can help me out with a script I'm working on.

If I have a colon seperated input file like this:

Jim:Smith:Smith, J (John)
Bob:Jones:Jones, BA (Bob)
John:Doe:Doe, J (John)

I want to check that the third field matches '$2', 'one_or_more_capital_letters' ('$1').

The trouble is, I can't find a way to add variables into regular expressions. Initially I was hoping something like /$2, [A-Z]+ \($1\)/ would work but I guess not...
 
A starting point:
awk -F: '!match($3,$2", [A-Z]+ \\("$1"\\)")' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks a lot, that worked perfectly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top