awk -F","
'BEGIN { #some variable assignment}
{ #some calculation and put values in array}
END {
year=#getting it from array and assume this will be 2014
month=#getting it from array and this will be 05
date=# getting it from array and this will be 20
rt_date=year"-"month"-"date (this will be 2014-05-20)
I need to find the week of the above date.
In normal case, using date command we can find the week easily.
e.g.
date -d "$rt_date" +%-V
but this is not properly working inside the awk command :(.
awk -v woy="$(date -d "$rt_date" +%-V)" -F","
'BEGIN { #some variable assignment}
{ #some calculation and put values in array}
END {
year=#getting it from array and assume this will be 2014
month=#getting it from array and this will be 05
date=# getting it from array and this will be 20
rt_date=year"-"month"-"woy (this will be 2014-05-20)
thanks for your reply.. I think my explanation might have given misunderstanding on the requirement.
let me explain again here.
I am getting the date string inside awk command as 2014-05-20
I need to get the week for this date.
assigning a global variable in awk is not giving me the correct week count for this date.
background:
> I am passing a csv file to this awk command. For each line there would be different date (it may not be the current date or same date).
> So using the date command or any in-build function of awk, i need to get the week for that date.
so can anyone kindly help on this... ???
Please let me know if you need any additional information.
You can use the mktime() and strftime() routines if your awk has them (gawk does). Here's a crude sample to give you an idea how it work. Check the "man gawk" page for more info
Thanks for you help.
It helped a lot but still need a small help. I need to pass the year, month and date awk variable to mktime and get the week for that date.
the below code is always returning 1 if we are passing the variables in any case.
can you help on this.