Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

sed for conky for weather

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
patrick013
Posts: 84
Joined: 2013-02-07 19:08

sed for conky for weather

#1 Post by patrick013 »

Hi,
This is what I get from terminal.

Code: Select all

$ inxi -xxxW 60610
Weather:   Conditions: 31 F (-1 C) - Overcast Wind: From the WSW at 15 MPH Humidity: 57%
           Pressure: 30.31 in (1026 mb) Wind Chill: 20 F (-6 C)
           Location: Chicago IL (US) Altitude: 178 ft
           Time: November 12, 3:22 PM CST Observation Time: November 12, 2:53 PM CST
I need to develop a sed line break before each text word with a colon for conky
to look like this. Manuals I looked at don't do it exactly right. Command would
be placed in conky to display weather info. The last line or three could be omitted
but that's not the main problem. An easy sed one-liner I hope.

Code: Select all

$ inxi -xxxW 60610 | sed ?
Weather:   
Conditions: 31 F (-1 C) - Overcast
Wind: From the WSW at 15 MPH
Humidity: 57%
Pressure: 30.31 in (1026 mb)
Wind Chill: 20 F (-6 C)
Location: Chicago IL (US) Altitude: 178 ft
Time: November 12, 3:22 PM CST
Observation Time: November 12, 2:53 PM CST
Thanks a bunch.

patrick

fruitofloom
Posts: 183
Joined: 2014-10-27 21:28

Re: sed for conky for weather

#2 Post by fruitofloom »

This doesn't do it:

Code: Select all

sed 's/ [[:alpha:] ]*: /\n&/g' test.txt
but perhaps you can carve it a bit.

https://stackoverflow.com/questions/723 ... -a-pattern

Well: you've probably been that far alread ... sorry
I searched a bit, i fooled a bit, i didn't get it sorted, but then thought: why not post my result.
Give me convenience or give me death.

kmathern
Posts: 603
Joined: 2011-02-05 19:20

Re: sed for conky for weather

#3 Post by kmathern »

This kind of works, though it has some blank lines:

Code: Select all

$ inxi -xxxW 60610|sed 's/Co/\nCo/;s/Wind:/\nWind:/;s/Hu/\nHu/;s/Pr/\nPr/;s/Wind Chill/\nWind Chill/;s/Loc/\nLoc/;s/Al/\nAl/;s/Time:/\nTime:/;s/Ob/\nOb/'
Weather:   
Conditions: 29 F (-2 C) - Overcast 
Wind: From the West at 14 MPH 
Humidity: 56%
           
Pressure: 30.32 in (1027 mb) 
Wind Chill: 18 F (-8 C)
           
Location: Chicago IL (US) 
Altitude: 178 ft
           
Time: November 12, 5:29 PM CST 
Observation Time: November 12, 4:53 PM CST
To get rid of the blank lines the (the 3rd sed command), I first needed to remove the ansi color codes (the 2nd sed cmd)

Code: Select all

$ inxi -xxxW 60610|sed 's/Co/\nCo/;s/Wind:/\nWind:/;s/Hu/\nHu/;s/Pr/\nPr/;s/Wind Chill/\nWind Chill/;s/Loc/\nLoc/;s/Al/\nAl/;s/Time:/\nTime:/;s/Ob/\nOb/'|sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g'|sed '/^[ \t]/d'
Weather:   
Conditions: 29 F (-2 C) - Overcast 
Wind: From the West at 14 MPH 
Humidity: 56%
Pressure: 30.32 in (1027 mb) 
Wind Chill: 18 F (-8 C)
Location: Chicago IL (US) 
Altitude: 178 ft
Time: November 12, 5:30 PM CST 
Observation Time: November 12, 4:53 PM CST

patrick013
Posts: 84
Joined: 2013-02-07 19:08

Re: sed for conky for weather

#4 Post by patrick013 »

kmathern wrote:To get rid of the blank lines the (the 3rd sed command), I first needed to remove the ansi color codes (the 2nd sed cmd)
Brilliant ! When I throw it into conky it's full of non-text visible items.
Do you have conky to take a look ? They need to be filtered out
somehow. In the terminal it looks great. THX.

patrick013
Posts: 84
Joined: 2013-02-07 19:08

Re: sed for conky for weather

#5 Post by patrick013 »

My attempt BTW. Still getting bombed out of conky.

Code: Select all

$ inxi -xxxw | sed -n 1,2p | awk '{gsub(/Conditions:/,"\n&");print}' | awk '{gsub(/Wind:/,"\n&");print}' | awk '{gsub(/Humidity:/,"\n&");print}' | awk '{gsub(/Pressure:/,"\b\b\b\b\b\b\b\b\b\b\b&");print}'  | awk '{gsub(/Wind Chill:/,"\n&");print}'
Weather:   
Conditions: 29 F (-2 C) - Overcast 
Wind: From the WNW at 14 MPH 
Humidity: 51%
Pressure: 30.33 in (1027 mb) 
Wind Chill: 18 F (-8 C) 

fruitofloom
Posts: 183
Joined: 2014-10-27 21:28

Re: sed for conky for weather

#6 Post by fruitofloom »

I think with a certain pattern, say word+colon, one will want to use regular expressions, instead of typing them in a list.
Stuff like this too: \b\b\b\b\b\b\b\b\b\b\b
In fact i think that is the main point of tools like sed, awk, perl and others (editors come to mind too. Well, sed is the streaming editor, right? ).
Give me convenience or give me death.

patrick013
Posts: 84
Joined: 2013-02-07 19:08

Re: sed for conky for weather

#7 Post by patrick013 »

fruitofloom wrote:I think with a certain pattern, say word+colon, one will want to use regular expressions, instead of typing them in a list.
A one-liner would be better. Problem still remains it won't go into conky right.

THX.

fruitofloom
Posts: 183
Joined: 2014-10-27 21:28

Re: sed for conky for weather

#8 Post by fruitofloom »

You might wanna give it a try at linuxquestions.org, and if that doesn't help (i highly doubt that) at unix.com and if that doesn't work at stackoverflow (where i am quite sure you will get the answer).
Good luck.
Give me convenience or give me death.

Post Reply