Issue
Given the following array in Shell Programming
foo=(spi spid spider spiderman bar lospia)
I would like to use GREP to search for all words in the array which has the 3 letters spi
Correct output : spi spi spider spiderman lospia
I have tried something like this
foo=(spi spid spider spiderman)
grep "spi" foo
But it seems it is wrong , what is the correct way to go about it ???
Solution
The following will print out all words that contain spi:
foo=(spi spid spider spiderman bar)
for i in ${foo[*]}
do
echo $i | grep "spi"
done
Answered By - CrazyCasta Answer Checked By - Robin (WPSolving Admin)