Search code examples
regexperlawksedscripting

Convert specific number date to show month


Want to convert for example that date:

02082012

In that case:
02 - Day
08 - Month
2012 - Year

For now I separate the date but not able to convert into month:

#echo "02082012"|gawk -F "" '{print $1$2 "-" $3$4 "-" $5$6$7$8}'
#02-08-2012

Expected view after convert and to catch all Months:

02-Aug-2012

Solution

  • straightforward:

    kent$ date -d "$(echo '02082012'|sed -r 's/(..)(..)(....)/\3-\2-\1/')" "+%d-%b-%Y"
    02-Aug-2012