When I run the following command on terminal,
awk /984/ $files | awk -F, \'{OFS=\",\";print $1,$4,$17}\'
where,
I think the problem is in the usage of () in your script. I tried a similar example and got the required output
myarray=(`ls *.sh`)
for f in ${myarray[@]}
do
echo $f
done
I think the code of yours should be changed as follows
result=(`awk /string/ $files | awk -F, '{OFS=",";print $1,$4,$17}'`)
To store variables in an array, output needs to be in a form like this:
result=$(one two "more data")
echo ${result[2]}
more data
Data separated by spaces. So tweak your output to give that format.
Can you give an example of what you get out of:
awk '/984/' $files | awk -F, '{OFS=",";print $1,$4,$17}'
It may be shorten to:
awk -F, '/984/ {OFS=",";print $1,$4,$17}' $files
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.