Put result of awk into an array

后端 未结 3 1385
北恋
北恋 2021-01-06 10:33

When I run the following command on terminal,

awk /984/ $files | awk -F, \'{OFS=\",\";print $1,$4,$17}\'

where,

         


        
3条回答
  •  执笔经年
    2021-01-06 11:15

    When you say:

    result=($(awk /string/ $files | awk -F, '{OFS=",";print $1,$4,$17}'))
    

    the output would be split by whitespace. Set IFS to a newline character, and you should see the desired result. Say:

    IFS=$'\n' result=($(awk /string/ $files | awk -F, '{OFS=",";print $1,$4,$17}'))
    

    instead to capture different lines of output into an array.

提交回复
热议问题