Hello, I want to run a field from an awk command through a command in bash.
For example my input file is
1,2,3
20,30,40
60,70,80
I want tot run $2 thought the command
date +%d/%m/%y -d"01/01/15 + $2 days -1 day"
and get the output
1,02/01/15,3
20,30/01/15,40
60,11/03/15,80
I'm stumped. Tried using
awk -v var=......
but can't seem to get it to work.
Any hints?
Thanks
Try using a while loop, for example something like (not tested):
while IFS=, read a b c
do
date +%d/%m/%y -d"01/01/15 + $b days -1 day"
done < inputfile
RudiC
3
If it HAS to be awk
, try
awk '{system("date +\"" $1 ",%d/%m/%y," $3 "\" -d\"01/01/15 + " $2 "days -1 day\"")}' FS=, file
1,02/01/15,3
20,30/01/15,40
60,11/03/15,80
or, slightly shorter,
awk '{system("date +\"" $1 ",%d/%m/%y," $3 "\" -d\"01/01/15 + " $2 - 1 "days\"")}' FS=, file
1,02/01/15,3
20,30/01/15,40
60,11/03/15,80