将awk的结果放入数组 [英] Put result of awk into an array
本文介绍了将awk的结果放入数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在终端上运行以下命令时,
awk /984/ $files | awk -F, '{OFS=",";print $1,$4,$17}'
哪里
files=`ls`
我得到以下输出:
2013/08/18 12:51:37,11,724
2013/08/18 12:48:02,227,84769
我希望创建一个脚本,运行该命令并将上述结果分配给数组:(将单独的行作为单独的元素)
I wish to create a script, run that command and assign the above result to an array in this way: (Separate lines as separate elements)
array[0] = 2013/08/18 12:51:37,11,724
array[1] = 2013/08/18 12:48:02,227,84769
但是
都不是
result=($(awk /string/ $files | awk -F, '{OFS=",";print $1,$4,$17}'))
也不,
result2=`awk /string/ $files | awk -F, '{OFS=",";print $1,$4,$17}'`
实现了我的目的.
如何获取我指定的数组?
How to get an array like I specified?
推荐答案
当您说:
result=($(awk /string/ $files | awk -F, '{OFS=",";print $1,$4,$17}'))
输出将被空格分隔.将IFS
设置为换行符,您将看到所需的结果.说:
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.
这篇关于将awk的结果放入数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文