Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash grep results into array

Tags:

arrays

grep

bash

In bash I'm trying to collect my grep results in array, each cell holding each line. I'm downloaing urls with this line

wget -O index -E $CurrentURL

and then i want to grep the 'index' file results (other urls) into array each line per cell, what should be the correct syntax?

Array=(grep "some expression" index)

??

like image 668
k-man Avatar asked Nov 20 '11 23:11

k-man


1 Answers

 readarray GREPPED < <(grep "some expression" index)
 for item in "${GREPPED[@]}"
 do
     # echo
     echo "${item}"   
 done

Oh, and combine those -v greps like so:

 egrep -v '\.(jpg|gif|xml|zip|asp|php|pdf|rar|cgi|html?)'
like image 138
sehe Avatar answered Nov 01 '22 23:11

sehe