Hello scriptor,
could you please try following and let me know if this helps you.
awk -v Date=$(date +%d) -v Month=$(date +%m) -v Year=$(date +%Y) 'BEGIN{print "Date stat1 stat2 stat3 stat4 stat5";split("Jan,Feb,Mar,Apr,may,Jun,Jul,Aug,Sept,Oct,Nov,Dec", array,",");MON=array[sprintf("%d",Month)];VAL=Date"-"MON"-"Year} NR==1{print VAL,$0;next} {printf("%"length(VAL)+1"s%s\n","",$0)}' Input_file | mailx -s"test_email" chumma@chumma.com
EDIT: Adding a non-one liner form of solution too here.
awk -v Date=$(date +%d) -v Month=$(date +%m) -v Year=$(date +%Y) 'BEGIN{
print "Date stat1 stat2 stat3 stat4 stat5";
split("Jan,Feb,Mar,Apr,may,Jun,Jul,Aug,Sept,Oct,Nov,Dec", array,",");
MON=array[sprintf("%d",Month)];
VAL=Date"-"MON"-"Year
}
NR==1{
print VAL,$0;
next
}
{
printf("%"length(VAL)+1"s%s\n","",$0)
}
' Input_file | mailx -s"test_email" chumma@chumma.com
EDIT2: Adding a little more modified solution where no hard coded first heading.
awk -v Date=$(date +%d) -v Month=$(date +%m) -v Year=$(date +%Y) 'BEGIN{
split("Jan,Feb,Mar,Apr,may,Jun,Jul,Aug,Sept,Oct,Nov,Dec", array,",");
MON=array[sprintf("%d",Month)];
VAL=Date"-"MON"-"Year
printf("%s%"length(VAL)+1"s %s %s %s %s\n","Date","stat1","stat2","stat3","stat4","stat5");
}
NR==1{
print VAL,$0;
next
}
{
printf("%"length(VAL)+1"s%s\n","",$0)
}
' Input_file | mailx -s"test_email" chumma@chumma.com
Thanks,
R. Singh