Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression to match a pattern inside awk command

Tags:

regex

awk

I need to write a regular expression to match the following pattern :

fltr_desc_name

that is.. "fltr" followed by an underscore followed by any number of words separated by underscore.

for example: I need a regular expression to match the following :

fltr_desc_name
fltr_nameone_nametwo
fltr_level_name_desc

and I am using it inside an "if" statement in "awk": for ex:

awk '/Transformation/ { if ($4=="Filter" && $5=="fltr_*") print $4,$5 }' filename  

please help me in writing the regular expression and tell me how to use regular expression inside an "if" condition inside "awk" command. Thank you.

like image 489
Karthik Avatar asked Jan 08 '13 10:01

Karthik


1 Answers

Need to use tilde character ~/ / in matching regular expressions in awk, i.e.

if ($5 ~ /fltr_*/)
like image 94
Wayne Doyle Avatar answered Jan 12 '23 23:01

Wayne Doyle