Pass awk field to a command line executed within awk

Hi,

I am trying to pass awk field to a command line executed within awk (need to convert a timestamp into formatted date).
All my attempts failed this far.

Here's an example.
It works fine with timestamp hard-codded into the command

echo "1381653229 something" |awk 'BEGIN{cmd="date -d @1381653229 +\"%m/%e/%y %H:%M\""; cmd|getline; close(cmd); date=$0;}{print date"|"$2}'

How do I do something like

echo "1381653229 something" |awk 'BEGIN{cmd="date -d @$1 +\"%m/%e/%y %H:%M\""; cmd|getline; close(cmd); date=$0;}{print date"|"$2}'

Thanks in advance.

You could do this, without troubling awk:

[user@host ~]$ set 1381653229 something
[user@host ~]$ echo "$(date -d @$1 +"%m/%e/%y %H:%M")|$2"
10/13/13 14:03|something
[user@host ~]$

Well, that was just an example.
Actually I need to run with a script on multiple files and fish designated fields out of them.
So, awk seems to be the tool.

$echo "1381653229 something" | while read a b;do echo $(date -d@$a +'%D %T')"|$b" ;done
10/13/13 10:33:49|something
$

balajesuri, ctsgnb

Thank you both.
After all did it your way.

:wink: