How to get system output in awk?

I want to save printf output to an array, as shown below:

op[i] = system( "printf \"%d\\n\" \"" SQ substr($1,i,1) "\"" )

but when I call them back, are they just 0 ?!

Do you know why!

+3
source share
1 answer

Do you want to

op[i] = sprintf("%d\n", SQ substr($1,i,1))

The way to capture output from an external command:

cmd = "date"
cmd | getline output
close(cmd)

http://www.gnu.org/software/gawk/manual/html_node/Getline_002fVariable_002fPipe.html#Getline_002fVariable_002fPipe

+8
source

All Articles