How can I pass variables from awk to a shell command?

前端 未结 5 1737
太阳男子
太阳男子 2020-12-01 04:14

I am trying to run a shell command from within awk for each line of a file, and the shell command needs one input argument. I tried to use system(), but it didn

5条回答
  •  不知归路
    2020-12-01 04:51

    You cannot grab the output of an awk system() call, you can only get the exit status. Use the getline/pipe or getline/variable/pipe constructs

    awk '{
        cmd = "your_command " $1
        while (cmd | getline line) {
            do_something_with(line) 
        }
        close(cmd)
    }' file
    

提交回复
热议问题