Here you can see that $6 will return the month... that will be in format of Jan, Feb, Mar, or ... Now I want to convert month to numeric. Like 1 for Jan, 2 for Feb, 3 for Mar...so on.
awk 'BEGIN { split("Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec", MON, "|"); for(N=1; N<=12; N++) I[MON[N]]=N; }
{ (rest of your code goes here) }'
Now you have an array MON where MON[1]="Jan", and an array I where I["Jan"]=1.
---------- Post updated at 12:11 PM ---------- Previous update was at 12:10 PM ----------
You've already been told "no". $Aug will pick a different field depending on what number Aug is. Variables don't work that way in awk. print Aug; will print 8. Print $Aug will print field number 8, whatever it is. I don't think you can solve your problem with -v since you can't go from a number to a variable name.
You can use a number as an array index, which is what I have done. Try my above solution, which builds arrays out of a string of months.
The -v solution will never work because variables don't work that way. You can't feed awk 8 and have awk decide "oh, there's a variable named Aug holding 8, you must mean it". It doesn't search for other variables with the same contents.
I may have stated it backwards, I["Jan"] will be 1 and MON[1] will be "Jan". Otherwise my solution does what you want.
From there you can understand why I need this... and I am not getting how to implement your code in my solution. I have used $6 for month in mon format, but I want to convert it into numeric.
Thanks.
---------- Post updated at 01:15 AM ---------- Previous update was at 12:57 AM ----------