- Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
- Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Collapse
You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:
- You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
- You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
- If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.
Logging in...
Previously on "Script for pulling values from an rss file"
Collapse
-
Cheers guys.
I also like Doodab's idea but can't find a free version of the tables or a formula.
Will have a looky at NFs feed parser but more as an exercise in technical masturbation since Platy and Contreras have solved it for me.
Rep will be forthcoming to all (Platy will have to wait a bit
)
Leave a comment:
-
Originally posted by Platypus View PostCode:cat $1 | grep "description.*Low" | sed 's/(/(/g' | sed 's/)/)/g' | sed 's/^.*\([0-9][0-9]:[0-9][0-9] - Low Tide ([.0-9][.0-9]*m)\).*\([0-9][0-9]:[0-9][0-9] - High Tide ([.0-9][.0-9]*m)\).*\([0-9][0-9]:[0-9][0-9] - Low Tide ([.0-9][.0-9]*m)\).*\([0-9][0-9]:[0-9][0-9] - High Tide ([.0-9][.0-9]*m)\).*$/\1+\2+\3+\4/' | tr '+' '\n'
Smart ArseOriginally posted by Contreras View PostCode:~$ sed 's/&[^;]*;/\n/g;/^..:.. - .* Tide \n/{s/\n//;P};D' tide.rss
Leave a comment:
-
sed is not cool for parsing xml, but here ya goOriginally posted by Pondlife View PostI have no idea how sed and awk work but I guess they are the tools for the job? What I want to do is be able to pull the High and low tide times and heights from inside the description tags using a shell script.
Any ideas?
TIA
Pondy
:
Code:~$ sed 's/&[^;]*;/\n/g;/^..:.. - .* Tide \n/{s/\n//;P};D' tide.rss 00:34 - Low Tide 1.40m 06:43 - High Tide 11.60m 12:58 - Low Tide 1.40m 19:05 - High Tide 11.70m ~$
Leave a comment:
-
Perhaps a slightly controversial suggestion, but why not work the numbers out yourself?
Leave a comment:
-
If the feed is always well-formed XML, I'd parse it as such. Much as I love XSLT I think it might be overkill for this case: just parsing it into a DOM and yanking the data out of that directly would be sufficient.
If the feed isn't always well-formed, which is often the case due to people thinking XML is "just text" (which it isn't) and can be generated by string concatenation (which it can, but not by most people), then a feedparser implementation would be a better choice: Universal Feed Parser should do the trick. On reflection, it's probably best just to use that, or one of its equivalents for your language of choice.
Leave a comment:
-
This
Outputs this:Code:cat $1 | grep "description.*Low" | sed 's/(/(/g' | sed 's/)/)/g' | sed 's/^.*\([0-9][0-9]:[0-9][0-9] - Low Tide ([.0-9][.0-9]*m)\).*\([0-9][0-9]:[0-9][0-9] - High Tide ([.0-9][.0-9]*m)\).*\([0-9][0-9]:[0-9][0-9] - Low Tide ([.0-9][.0-9]*m)\).*\([0-9][0-9]:[0-9][0-9] - High Tide ([.0-9][.0-9]*m)\).*$/\1+\2+\3+\4/' | tr '+' '\n'
00:34 - Low Tide (1.40m)
06:43 - High Tide (11.60m)
12:58 - Low Tide (1.40m)
19:05 - High Tide (11.70m)
P.S. Yes, it's "old fashioned" regex
Leave a comment:
-
Should be relatively straight forward to do it with a regular expression (regex) as the data will be in a consistent format. ie always low tide height, high tide height, low tide height, high tide height with the values always in the same format nn:nn n.nnm for time and height respectively. You might have to frig it a bit to account for exceptional tide heights (10m +) if they exist.Originally posted by Pondlife View PostI have an rss file containing the following;
I have no idea how sed and awk work but I guess they are the tools for the job? What I want to do is be able to pull the High and low tide times and heights from inside the description tags using a shell script.Code:<?xml version="1.0" encoding="utf-8"?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> <title>Some Tide Times</title> <link>http://www.tidetimes.org.uk/Some-tide-times</link> <description>Some tide times.</description> <lastBuildDate>Wed, 27 Mar 2013 00:00:00 GMT</lastBuildDate> <language>en-gb</language> <atom:link href="http://www.tidetimes.org.uk/Some-tide-times.rss" rel="self" t ype="application/rss+xml"/> <item> <title>Some Tide Times for 27th March 2013</title> <link>http://www.tidetimes.org.uk/Some-tide-times</link> <guid>http://www.tidetimes.org.uk/Some-tide-times</guid> <pubDate>Wed, 27 Mar 2013 00:00:00 GMT</pubDate> <description><a href="http://www.tidetimes.org.uk" title="Tide Times">Ti de Times</a> & Heights for<br/><a href="http://www.tidetimes. org.uk/Some-tide-times" title="Some tide times">Some</a> on 27th Mar ch 2013<br/><br/>00:34 - Low Tide (1.40m)<br/>06:43 - High Tide (11.60m)<br/>12:58 - Low Tide (1.40m)<b r/>19:05 - High Tide (11.70m)<br/></description> </item> </channel> </rss>
Any ideas?
TIA
Pondy
I'm rusty on this stuff as I havent' written shell scripts in years but you should be able to use an appropriately crafted regex in sed to ditch everything up to the first tide time then strip out the extraneous rubbish between the data you want using pattern matching to pick out the bits you want to keep and dump the whole lot into a file.
Sed itself is easy , basic pattern is :
sed -e 's/oldstuff/newstuff/g' inputFileName > outputFileName
Which is basically saying run sed in execute mode (-e), search the input file for a pattern that matches "oldstuff" and replace it with "newstuff" and put the whole thing into a new file when your done.
Replace oldstuff and newstuff with the regex to identify the data you want and the desired output and you should be away.
Of course figuring out the regex is going to be the fun part. especially as you are going to have to use back references to hold the bits you want and put them into the output file.
If you are running is a command line setting it may be easier to do the whole thing in Perl if you have it available, although you will still need to get your head around the regex.
Leave a comment:
-
You probably want to use XSL.Originally posted by Pondlife View PostI have an rss file containing the following;
I have no idea how sed and awk work but I guess they are the tools for the job? What I want to do is be able to pull the High and low tide times and heights from inside the description tags using a shell script.Code:<?xml version="1.0" encoding="utf-8"?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> <title>Some Tide Times</title> <link>http://www.tidetimes.org.uk/Some-tide-times</link> <description>Some tide times.</description> <lastBuildDate>Wed, 27 Mar 2013 00:00:00 GMT</lastBuildDate> <language>en-gb</language> <atom:link href="http://www.tidetimes.org.uk/Some-tide-times.rss" rel="self" t ype="application/rss+xml"/> <item> <title>Some Tide Times for 27th March 2013</title> <link>http://www.tidetimes.org.uk/Some-tide-times</link> <guid>http://www.tidetimes.org.uk/Some-tide-times</guid> <pubDate>Wed, 27 Mar 2013 00:00:00 GMT</pubDate> <description><a href="http://www.tidetimes.org.uk" title="Tide Times">Ti de Times</a> & Heights for<br/><a href="http://www.tidetimes. org.uk/Some-tide-times" title="Some tide times">Some</a> on 27th Mar ch 2013<br/><br/>00:34 - Low Tide (1.40m)<br/>06:43 - High Tide (11.60m)<br/>12:58 - Low Tide (1.40m)<b r/>19:05 - High Tide (11.70m)<br/></description> </item> </channel> </rss>
Any ideas?
TIA
Pondy
Sed and awk aren't really suited to xml.
Leave a comment:
-
Script for pulling values from an rss file
I have an rss file containing the following;
I have no idea how sed and awk work but I guess they are the tools for the job? What I want to do is be able to pull the High and low tide times and heights from inside the description tags using a shell script.Code:<?xml version="1.0" encoding="utf-8"?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> <title>Some Tide Times</title> <link>http://www.tidetimes.org.uk/Some-tide-times</link> <description>Some tide times.</description> <lastBuildDate>Wed, 27 Mar 2013 00:00:00 GMT</lastBuildDate> <language>en-gb</language> <atom:link href="http://www.tidetimes.org.uk/Some-tide-times.rss" rel="self" t ype="application/rss+xml"/> <item> <title>Some Tide Times for 27th March 2013</title> <link>http://www.tidetimes.org.uk/Some-tide-times</link> <guid>http://www.tidetimes.org.uk/Some-tide-times</guid> <pubDate>Wed, 27 Mar 2013 00:00:00 GMT</pubDate> <description><a href="http://www.tidetimes.org.uk" title="Tide Times">Ti de Times</a> & Heights for<br/><a href="http://www.tidetimes. org.uk/Some-tide-times" title="Some tide times">Some</a> on 27th Mar ch 2013<br/><br/>00:34 - Low Tide (1.40m)<br/>06:43 - High Tide (11.60m)<br/>12:58 - Low Tide (1.40m)<b r/>19:05 - High Tide (11.70m)<br/></description> </item> </channel> </rss>
Any ideas?
TIA
PondyTags: None
- Home
- News & Features
- First Timers
- IR35 / S660 / BN66
- Employee Benefit Trusts
- Agency Workers Regulations
- MSC Legislation
- Limited Companies
- Dividends
- Umbrella Company
- VAT / Flat Rate VAT
- Job News & Guides
- Money News & Guides
- Guide to Contracts
- Successful Contracting
- Contracting Overseas
- Contractor Calculators
- MVL
- Contractor Expenses
Advertisers
Contractor Services
CUK News
- New UK crypto rules now apply. Here’s how mandatory reporting affects contractors Today 07:03
- What the Ray McCann Loan Charge Review means for contractors Yesterday 06:21
- IT contractor demand defied seasonal slump in December 2025 Jan 13 07:10
- Five tax return hacks for contractors as Jan 31st looms Jan 12 07:45
- How to land a temporary technology job in 2026 Jan 9 07:01
- Spring Forecast 2026 ‘won’t put up taxes on contractors’ Jan 8 07:26
- Six things coming to contractors in 2026: a year of change, caution and (maybe) opportunity Jan 7 06:24
- Umbrella companies, beware JSL tunnel vision now that the Employment Rights Act is law Jan 6 06:11
- 26 predictions for UK IT contracting in 2026 Jan 5 07:17
- How salary sacrifice pension changes will hit contractors Dec 24 07:48

Leave a comment: