Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Location: Apr-Oct Enderby, BC Canada Oct-Mar Somewhere warm
Distribution: Debian 6 and 7
Posts: 46
Rep:
Extract text from text
I have a bash script (.sh file) that puts weather conditions on an image. I am having problems getting the -30 near the end of the string. The text file that I am geting the info from is fairly large but this is the rows of text I am trying to get.
Did you look at what got assigned ?.
There are two matches on that file, which complicates things a little. Not so much if you (always) want the first occurrence.
I might be inclined to use a bash array to hold all the returned fields.
Location: Apr-Oct Enderby, BC Canada Oct-Mar Somewhere warm
Distribution: Debian 6 and 7
Posts: 46
Original Poster
Rep:
Quote:
Originally Posted by syg00
Did you look at what got assigned ?.
There are two matches on that file, which complicates things a little. Not so much if you (always) want the first occurrence.
I might be inclined to use a bash array to hold all the returned fields.
Yes the query didn't pick up anything as it looked at the first occurrence. I had this to find the correct place to start from
Ahhhh - hang on; are you still using windchillStr ?. Don't.
Use my command is place of both - sorry, I should have been clearer about that. As for only one result, which one ?. What about if there are more - 3, 5, 20, ...
Data providers change format ever so often too.
one thought:
if you want to get content from a html page, why don't you use the same logic that is at work inside your browser?
it's called xpath (ok i'm simplifying things here, but just read the intro to the tutorial) and there's a command line utility called "xmllint" (included in a package usually called "libxml2" iirc).
i was using the same sed/grep-logic for my weather script - until i bit the bullet and changed it all to xmllint.
have a look at my weather conky & shell script in my github stuff link below.
Location: Apr-Oct Enderby, BC Canada Oct-Mar Somewhere warm
Distribution: Debian 6 and 7
Posts: 46
Original Poster
Rep:
Quote:
Originally Posted by syg00
I used the command I gave you earlier.
Ahhhh - hang on; are you still using windchillStr ?. Don't.
Use my command is place of both - sorry, I should have been clearer about that. As for only one result, which one ?. What about if there are more - 3, 5, 20, ...
Data providers change format ever so often too.
I am just using your code and it does not find the Wind Chill Temperature when run on the file I attached. It return nothing at all ?
The file format is pretty static it changed in the summer and uses Humidex instead of Wind Chill but nothing major in the last few years.
Location: Apr-Oct Enderby, BC Canada Oct-Mar Somewhere warm
Distribution: Debian 6 and 7
Posts: 46
Original Poster
Rep:
Quote:
Originally Posted by ondoho
one thought:
if you want to get content from a html page, why don't you use the same logic that is at work inside your browser?
it's called xpath (ok i'm simplifying things here, but just read the intro to the tutorial) and there's a command line utility called "xmllint" (included in a package usually called "libxml2" iirc).
i was using the same sed/grep-logic for my weather script - until i bit the bullet and changed it all to xmllint.
have a look at my weather conky & shell script in my github stuff link below.
I might have to look into this at some time but at 66 learning new things does not come easy
Location: Apr-Oct Enderby, BC Canada Oct-Mar Somewhere warm
Distribution: Debian 6 and 7
Posts: 46
Original Poster
Rep:
Answer found.
The answer to my problem is below:
Code:
## Just add the 'q' command to make
## sed quit after it prints the first match
windchill=$(sed -nr '/Wind Chill/{n;n;s/.*>(.*)<.*/\1/p;q}' "$weatherFile")
I also found that I could use the .xml file instead of the web page text.
In the US, I would never use a webpage to get weather. That's the hard way. It's easy enough to get actual text weather reports from the NWS for any airport which reports weather, and they're easier to parse. But I don't know about the Great White North, things may be very different up there. :-P
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.