On Thu, Jun 3, 2010 at 12:58 PM, Richard Weait <span dir="ltr"><<a href="mailto:richard@weait.com">richard@weait.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I have a simple screen-scrape to do.<br>
<br>
>From the command line it works fine<br>
<br>
wget -q -O - <a href="http://www.openstreetmap.org/stats/data_stats.html%7C" target="_blank">http://www.openstreetmap.org/stats/data_stats.html|</a> grep<br>
"<td>Number of users" | sed -e 's/[:a-zA-Z <>/:]//g'<br>
<br>
it returns the plain number<br>
<br>
262086<br>
<br>
Cool, now to add it to a script<br>
<br>
This works fine<br>
GETTEE=`wget -q -O -<br>
<a href="http://www.openstreetmap.org/stats/data_stats.html%7C" target="_blank">http://www.openstreetmap.org/stats/data_stats.html|</a> grep "<td>Number<br>
of users" | sed -e 's/[:a-zA-Z <>/:]//g'`<br>
echo "GETTEE = $GETTEE"<br>
<br>
gives:<br>
GETTEE = 262086<br>
<br>
But.  I want to grab some other data from the same page, so I want to<br>
wget once, then grep / sed a couple of times.  And I'm breaking it.<br>
The page appears to have been stripped of its \n and so grepping the<br>
line I want is failing.<br>
<br>
GETTEE=`wget -q -O - <a href="http://www.openstreetmap.org/stats/data_stats.html%60" target="_blank">http://www.openstreetmap.org/stats/data_stats.html`</a><br>
echo "GETTEE = $GETTEE"<br>
<br>
This returns a mess.<br>
<br>
The quick and dirty is to wget four times for four numbers, but I<br>
don't want to do that.  How do I assign the wget to a variable and<br>
keep \n ?<br></blockquote><div><br>This is not fair for whoever is hosting the server.<br><br>Do the wget once, using<br><br>wget -q -O /tmp/osm.html <br><br>Then parse that file as many times as you want for whatever you want.<br>
</div></div>-- <br>Khalid M. Baheyeldin<br><a href="http://2bits.com">2bits.com</a>, Inc.<br><a href="http://2bits.com">http://2bits.com</a><br>Drupal optimization, development, customization and consulting.<br>Simplicity is prerequisite for reliability. --  Edsger W.Dijkstra<br>
Simplicity is the ultimate sophistication. --   Leonardo da Vinci<br>