When I run the following command on terminal,
awk /984/ $files | awk -F, '{OFS=",";print $1,$4,$17}'
where,
files=`ls`
I get this output:
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
BUT,
neither,
result=($(awk /string/ $files | awk -F, '{OFS=",";print $1,$4,$17}'))
nor,
result2=`awk /string/ $files | awk -F, '{OFS=",";print $1,$4,$17}'`
fulfills my purpose.
How to get an array like I specified?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With