Regular exp in awk

Hi all,
One small doubt, reg exp in awk, is it possible to extract the match of regular expression like in perl?

eg:
B R16288 Map3_NoCat
B R16067 Map4_NoCat
B R16647 Map3_NoCat
B R16450 Map3_NoCat
B R16106 Map6_NoCat
B R16000 Map3_NoCat
B R16395 Map3_NoCat
B R16243 Map3_NoCat
B R16023 Map12_NoCat
B R16421 Map3_NoCat

if I wanna extract the digits after Map, in perl I could say

 /Map(\d*)/  print $1

is there any direct way in awk for it?

awk:

awk -F"[ _]" '{sub(/Map/,"",$3); print $3}' infile

sed:

sed 's/.*Map\([0-9]\+\)_.*/\1/g' infile
#!/bin/bash
while read -r line
do
   line=${line##*Map}
   echo ${line%_*}
done < myfile

@zaxxon:
in your awk script

Code:
  awk -F"[ _]" '{sub(/Map/,"",$3); print $3}' infile

you r deleting the 'map', but what i want is to store the digits after map in order to do some logical test (say if the digit is > 5 then print the whole line)

Geo

No, in traditional awk you can't do that, as awk doesn't support back references. If you use Gnu awk (gawk), you could use the gensub()-function, which supports back references. If you don't have gawk, use sed instead.

HTH

Chris

@gvj

Yes, since that was what you asked for - if you have additional requests, please let it not sound as if there was missing someting in the answer to the original question, ty :wink:

awk -F"[ _]" '{a=$0; sub(/Map/,"",$3); if($3 > 5) print a}' infile
B R16106 Map6_NoCat
B R16023 Map12_NoCat

Another approach:

awk -F "Map|_" '$2 > 5' file