Need help extracting string from a file

rated by 0 users
This post has 5 Replies | 1 Follower

Top 500 Contributor
Posts 5
pierrelab Posted: 03-21-2012 6:49 PM

I'm new at PowerShell and thanks to this forum I was able to grab data from my weather station to be used in my home automation system and it works very well. 

Now I need to look at the forecast to display in my home automation touchscreen and to prevent watering if the chances of rain are over 50% for example.

I wrote a script to import  forecast from NOAA and it's lots of HTML codes. 

I want to extract everything from Tonight to the next <br> and save it in a text file:

The file content looks like this:
<table width="670" border="0" align="left" cellpadding="0" cellspacing="0"><tr valign ="top"><td valign="top" align="left" colspan="2"><br>Tonight: A 50 percent chance of showers, mainly after 1am.  Cloudy, with a low around 53. East northeast wind between 3 and 7 mph.  New rainfall amounts of less than a tenth of an inch possible. <br>....

I really need help :)

Thank you

 

Not Ranked
Posts 3

[regex]::matches($html,'(Tonight.*)(?=)')[0].value | Out-File weather.txt

Smile

 

Top 500 Contributor
Posts 5

Here is what I did

 

$html = Get-Content "C:\forecast.txt"

[regex]::matches($html,'(Tonight.*)(?=)')[0].value | Out-File C:\weather.txt

 

 

It creates a  file from Tonight to the end of the file, I'm very close but I'm sure I'm missing lots of things, darn newbie Zip it!

 

Continuing poking Powershell.com 

Top 500 Contributor
Posts 5

This one work well, Thank you RMCK

$html = Get-Content "C:\forecast.txt"

[regex]::matches($html,'(Tonight.*)(?=)')[0].value | Out-File C:\weather.txt

Now I need to limit the extraction to the next "<br> <br>" I tried to modify RMCK's line but all I did was to create an error generator lol  

Top 500 Contributor
Posts 5

[:'(] Everything I try fails... I'm sure there is way to do it but I'm too green to even think about a solution.

 

Anyone can help?

Thank you

Top 500 Contributor
Posts 5

No one? 

Page 1 of 1 (6 items) | RSS
Copyright 2012 PowerShell.com. All rights reserved.