LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Help separating a value (https://www.linuxquestions.org/questions/linux-software-2/help-separating-a-value-712276/)

OverlordSquishy 03-17-2009 10:26 AM

Help separating a value
 
Hey,

I'm working on a project for a Web Server administration class. We can use either IIS or Apache for the project and I've chosen to use Apache because I have very little experience administrating Linux and Linux applications.

What I'm trying to do is retrieve stock information and use it to make an automated stock-trading program. So far, I've got as far as isolating the line containing the information I need, but haven't made much progress since.

I've got the line:
<td width="1%" class=val><span id="ref_694653_op">320.18</span></td>

and I need to be able to pull 320.18 out of the line. This value will change. I've looked into using awk and Perl to do this (as I have some, though little experience with both) and so far no luck.

Any help would be greatly appreciated.

rizwanrafique 03-17-2009 12:06 PM

Try this one in perl:
Code:

#!/user/bin/perl

'<td width="1%" class=val><span id="ref_694653_op">320.18</span></td>' =~ m/<.*><.*>([0-9\.]+)<.*>/;

print $1;

This is a solution but a horrible one because HTML can't be relied upon for data at all. For example, imagine the scenario where the website inserts newline characters after each tag close. Try to find an xml/rss feed from the provider and then parse that. You'll get more reliable results.

Kenhelm 03-17-2009 03:24 PM

Try
Code:

echo "$line" | sed 's/<[^>]*>//g'
320.18



All times are GMT -5. The time now is 12:29 AM.