PDA

View Full Version : Split a returned list of values in Bash?



fuzzyslippers
November 1st, 2010, 11:02 PM
I have the code
#!/bin/sh
curl http://thepiratebay.org/top/all --silent -O temp1
TEMP="cat temp1"
URLLIST='$TEMP | grep "<div.*><a href=.*>.*</a>" | sed -e"s@<div.*><a@@g" | sed -e"s@</a></div>@@g" | grep ".*href=.*" | sed -e "s@href=@@g" -e "s@class=.*>@@g" -e "s@\" .*@@" -e "s@\"@@g" -e "s@.*/@http://thepiratebay.org/@g"'
OLD_IFS="$IFS"
IFS="\n"
for s in $URLLIST; do
echo $s
done
which I would like to index the top 100 torrents from The Pirate Bay, but when I run the script, it only returns the actual text from the variable, any suggestions?:confused:

spjackson
November 1st, 2010, 11:13 PM
#!/bin/sh
curl http://thepiratebay.org/top/all --silent -O temp1
TEMP="cat temp1"
URLLIST='$TEMP | grep "<div.*><a href=.*>.*</a>" | sed -e"s@<div.*><a@@g" | sed -e"s@</a></div>@@g" | grep ".*href=.*" | sed -e "s@href=@@g" -e "s@class=.*>@@g" -e "s@\" .*@@" -e "s@\"@@g" -e "s@.*/@http://thepiratebay.org/@g"'

I think you intended backticks here, not single-quotes, but $() is better, thus:


URLLIST=$($TEMP | grep "<div.*><a href=.*>.*</a>" | sed -e"s@<div.*><a@@g" | sed -e"s@</a></div>@@g" | grep ".*href=.*" | sed -e "s@href=@@g" -e "s@class=.*>@@g" -e "s@\" .*@@" -e "s@\"@@g" -e "s@.*/@http://thepiratebay.org/@g")

fuzzyslippers
November 1st, 2010, 11:32 PM
Thanks a lot, I feel dumb for not realizing that >.<