- 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'
Originally posted by Contreras View PostCode:~$ sed 's/&[^;]*;/\n/g;/^..:.. - .* Tide \n/{s/\n//;P};D' tide.rss
Leave a comment:
-
Originally 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
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:
-
Originally posted by Pondlife View PostI have an rss file containing the following;
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:
-
Originally posted by Pondlife View PostI have an rss file containing the following;
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;
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
- Streamline Your Retirement with iSIPP: A Solution for Contractor Pensions Sep 1 09:13
- Making the most of pension lump sums: overview for contractors Sep 1 08:36
- Umbrella company tribunal cases are opening up; are your wages subject to unlawful deductions, too? Aug 31 08:38
- Contractors, relabelling 'labour' as 'services' to appear 'fully contracted out' won't dupe IR35 inspectors Aug 31 08:30
- How often does HMRC check tax returns? Aug 30 08:27
- Work-life balance as an IT contractor: 5 top tips from a tech recruiter Aug 30 08:20
- Autumn Statement 2023 tipped to prioritise mental health, in a boost for UK workplaces Aug 29 08:33
- Final reminder for contractors to respond to the umbrella consultation (closing today) Aug 29 08:09
- Top 5 most in demand cyber security contract roles Aug 25 08:38
- Changes to the right to request flexible working are incoming, but how will contractors be affected? Aug 24 08:25
Leave a comment: