BEGIN {
monthA="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
monN=split(monthA, monA, FS)
# invert a monA array to be indexed by the NAME of the month
for(i=1; i<=monN; i++) {
monA[monA]=i
delete monA
}
}
{
_day=substr($3,1,2)
_mon=substr($3,3,3)
_year=substr($3,6)
printf("%4d%02d%02d%s%s\n", _year, monA[_mon], _day, OFS, $0)
}
Or all in ksh:
#!/bin/ksh
monthList='JanFebMarAprMayJunJulAugSepOctNovDec'
month2number() # $1 = month
{
typeset monthName="${1}"
typeset idx;
idx=${monthList%%${monthName}*}
printf "%02d" "$(( (${#idx} + 3 ) / 3 ))"
}
while read one two date four junk
do
_day=$(echo ${date} | sed 's/^\(..\).*/\1/')
_mon=$(echo ${date} | sed 's/^..\(...\).*/\1/')
_year=$(echo ${date} | sed 's/.*\(....\)/\1/')
echo "${_year}$(month2number ${_mon})${_day} " " $one " " $two " " $date " " $four"
done < abc.txt | sort -n | cut -d' ' -f2-