The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #6 (permalink)  
Old 07-05-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,342
To match dates you can use a format like YYYYMMDDHH, an example to convert the date format Mar 17 16:44:03 2009 to 2009031716


Code:
echo "Mar 17 16:44:03 2009"|
awk -F" |:" '
BEGIN {
  a="Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"
  split(a,m,",")
  for(i=1;i<13;i++)
    n[m[i]]=i
}
{printf("%s%02d%02d%s\n", $6, n[$1], $2, $3)}
'

Use nawk or /usr/xpg4/bin/awk on Solaris if you get errors.