Using awk to filter and print matching regular expression

I am trying to figure out how to use awk to only print matching regular expression, see grep example in code snippet listed below. Something like this
----code start----
GetDate='Blabla - Blala (06.29.09)'
echo $GetDate | awk '/[:digit:{2}.{1}:digit:{2}.{1}:digit:{2}]/ {print}'
----code end----
but I only want to print the matching pattern like shown in my grep example.

Thanks for any help.
GetDate='Blabla - Blala (06.29.09)'
echo $GetDate | grep -E -o '[[:digit:]]{2}.{1}[[:digit:]]{2}.{1}[[:digit:]]{2}'

Open in new window

LVL 1
illtbaguAsked:
Who is Participating?
 
ozoCommented:
Did you get an error?
If mawk 1.3.3 does not support [[:digit:]] you might instead use
GetDate='Blabla - Blala (06.29.09)'
echo $GetDate | awk 'match($0,/[0-9][0-9]\.[0-9][0-9]\.[0-9][0-9]/){print substr($0,RSTART,RLENGTH)}'
0
 
ozoCommented:
echo $GetDate | awk 'match($0,/[[:digit:]][[:digit:]]\.[[:digit:]][[:digit:]]\.[[:digit:]][[:digit:]]/){print substr($0,RSTART,RLENGTH)}'
0
 
illtbaguAuthor Commented:
For whatever reason that didn't work.
-----
awk -W version
mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan
compiled limits:
max NF             32767
sprintf buffer      1020
0
 
ghostdog74Commented:

#!/bin/bash
GetDate='Blabla (06.29.00) - Blala (06.29.09)'
echo $GetDate | awk '{ 
 for(i=1;i<=NF;i++){
    f=0
    gsub(/\(|\)/,"",$i)
    m=split($i,t,".")
    if (m==3) {
        for(o=1;o<=m;o++){
            if(t[o]+0!=t[o]){ f=1 ;break}        
        }
        if(!f){ 
            for(o=1;o<=m;o++) {
                if(o==m) printf t[o]
                else printf t[o]"." 
            }
            print ""
        }    
    }
 }
}'

Open in new window

0
 
illtbaguAuthor Commented:
ozo,
That did the trick, thanks. It looks like it doesn't supports the newer posix character sets [[:digit:]].
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.