Reputation: 104
I have the following comand:
grep RJAVA | grep -v grep | wc -l ' | sort | cut -d':' -f2 | cut -d' ' -f2
After executing this, I get the following result :
10 0 0 10
I would like to put all these numbers into a bash array so that I can loop through the array. I tried using xargs but couldn't make it work. Any suggestion ?
Upvotes: 0
Views: 452
Reputation: 129481
this should work:
array=($( YOUR_ENTIRE_PIPED_COMMAND ))
BTW, the command above seems broken - you are missing the input to the first grep
(either filnames, or pipe into it)
Upvotes: 3
Reputation: 11
you could try tr:
IN="10 0 0 10"
arr=$(echo $IN | tr " " "\n")
for x in $arr
do
echo "> [$x]"
done
Regards, Edi
Upvotes: -1