On Thu, Jun 3, 2010 at 1:24 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;">
<div><div></div><div class="h5">On Thu, Jun 3, 2010 at 1:09 PM, Khalid Baheyeldin <<a href="mailto:kb@2bits.com">kb@2bits.com</a>> wrote:<br>
> On Thu, Jun 3, 2010 at 12:58 PM, Richard Weait <<a href="mailto:richard@weait.com">richard@weait.com</a>> wrote:<br>
>><br>
>> 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>
><br>
> This is not fair for whoever is hosting the server.<br>
<br>
</div></div>Right. That's why I'm here.<br>
<div class="im"><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>
<br>
</div>But no way to avoid all those disk calls? The assignment to the<br>
variable kills the \n or something?<br></blockquote><div><br>Yes, it does. It is converted to spaces once you read it in a variable.<br><br>Makes things like this useful (at least in some use cases, not yours):<br><br>cat > myfile<br>
first<br>second<br>third<br>^D<br><br>for WORD in `cat myfile`<br>do<br> # $WORD now contains first<br>done<br><br>But looking at the HTML page, there is only one occurrence of the string<br>you are looking for, so it is irrelevant if you do it from a variable or from<br>
a file (code wise).<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>