> Hi all,
> I want to write a shell script to get a part of the website content.
> For example.
> The website www.abc.com has the following content.
> <html>
> <body>
> You can buy whatever you want.<br>
> The price of the car is 100. The price of the ship is 30.
> </body>
> </html>
> I only want to get "100" from the above website.
> I write the following script to get the whole sentence.
> lynx -dump http://www.abc.com/index.html | grep car
> Is is possible to write a script to get the "100" only??
I assume you want to read a variable value (the car price) in a line where
the word "car" appears.
If the line in the HTML keeps constant, and only the car price changes,
you could use:
lynx -dump www.abc.com/index.html | awk '{if (match($0, /car/)) print $7}'
where the magic number 7 refers to the 7th record (100, i.e car price) in
a line that matches car.
But thats quite dodgy, and falls over if the word car appears in other
lines in the HTML document, or if something else changes.
You can read the lines and split them up with a "while" loop, and using
"read".
I have done that analyzing a line of a httpd log file in a bash script on
my Web page (see footer, go "scripting", "log files").
That's cumbersome, but you check each record separately, and it's very
flexible.
-- avs
Andre van Straaten
http://www.vanstraatensoft.com
______________________________________________