You don't need both
head and
awk. The latter will do it all:
Code:
... | awk 'NR==1 { print $2; exit; }'
However, you might save the whole HTTP response into a temp file using
/bin/tempfile so you can also extract the title without querying the server a second time.
The title should be in the
title element and you can extract that from your
curl output using
grep if it is all on one line, or even if it is split over multiple lines:
Code:
grep -m 1 -P -z -o '(?s)(?<=<title>).*?(?=</title>)'
... if your version of
grep supports PCRE so you can use
positive look-behind and look-ahead assertions to just print only the title itself.
However, speaking of perl, the direction you seem to be heading you should be using perl for this. Take a look at the CPAN module LWP and also any HTML parsing module like HTML::TokeParser or one of the others.
Also, be sure to take it easy on the target site. Add some waits inside your loop and maybe rate limit the download as well.