awk - Assign variable result of system function

0

I would like to assign variable result of system function:

awk 'BEGIN{x=system("cut -d \" \" -f 1 ol");print x}'

Input "ol":

1

Result:

1
0

diego9403

Posted 2015-09-01T07:28:56.777

Reputation: 807

Answers

1

I don't think there is a direct easy way to do that. You have to fall back on temporary files or on this method (contents of 'input': "value in ol"):

 awk -v cut_result=$( awk 'BEGIN{system("cut -d \" \" -f 1 ol")}' ) '{print $0, cut_result}' input

result: "value in ol 1"

So the output of awk is turned into a variable that's fed into another invocation of awk as the variable "cut_result".

Erik Bryer

Posted 2015-09-01T07:28:56.777

Reputation: 21