![]() |
question about piping grep into sed into xargs for geektool weather script
Hi, I'm working with unix on Mac OSX. I'm learning how to work with unix by creating geektool scripts. I want the following output:
Clear, 56.2° F what I'm getting is this: Clear 56.2 °F very slight change (addition of a comma, removal of extra space produced by xargs), I know, but I'm trying to learn how to control output from the following: Code:
curl -s http://api.wunderground.com/api/key/...6.1.99999.json | egrep --color '"weather"|"temp_f"' | sed 's/[[:blank:]"[:alpha:]_]*:"*\([[:alpha:][:blank:][:digit:].]*\)"*,/\1/' | xargs -n2 | xargs -I% echo % "°F"thanks in advance |
You can use printf instead of echo it's more versatile.
|
I can see from the man page for printf that its probably what I'm looking for. But could you please provide an example? below is example output from the API
Code:
{Thanks again. |
Can't you use awk to do all the work instead of multiple commands and pipes?
I'm not able to test this on OS-X, but this one-liner seems to work on linux when using the output ptovided in post #3: Code:
awk -F[:,] '/"weather"/ { gsub(/"/,"") ; WEATHER=$2 } /"temp_f"/{ TEMP=$2 }END{ print WEATHER",",TEMP,"F" }'Code:
awk -F[:,] ' # set multiple separators (: and ,)Code:
$ awk -F[:,] '/"weather"/ { gsub(/"/,"") ; WEATHER=$2 } /"temp_f"/{ TEMP=$2 }END{ print WEATHER",",TEMP,"F" }' api.output |
Thanks for your code, druuna. the following is giving me an error on OSX:
Code:
curl -s http://api.wunderground.com/api/9906888802114107/conditions/q/zmw:93546.1.99999.json" | awk -F[:,] '/"weather"/ { gsub(/"/,"") ; WEATHER=$2 } /"temp_f"/{ TEMP=$2 }END{ print WEATHER",",TEMP,"F" }'Code:
-bash: syntax error near unexpected token `)'Code:
curl -s "http://api.wunderground.com/api/9906888802114107/conditions/q/zmw:93546.1.99999.json" | awk '/"weather"/'Code:
curl -s "http://api.wunderground.com/api/9906888802114107/conditions/q/zmw:93546.1.99999.json" | awk '/"weather"/ { gsub(/"/,""); print $1 }'Code:
curl -s "http://api.wunderground.com/api/9906888802114107/conditions/q/zmw:93546.1.99999.json" | awk -F[:,] '/"weather"/ { gsub(/"/,""); WEATHER=$2 } /"temp_f"/ { TEMP=$2 } END { print WEATHER",",TEMP,"°F" } 'Code:
Clear, 21.8 °F |
Quote:
Code:
# without the space |
| All times are GMT -5. The time now is 04:33 PM. |