Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am in the process of making a bash script to scrape a weather.com to get the weather report. I need to process a line of text that has an unusual character. Here is the text:

30°FHigh 35°High 52°High 45°High 43°High

There is a small circle between the numbers and the letters. Here is the code:

#!/bin/bash

clear

lynx --dump http://www.weather.com/weather/5-day/New+York+NY+10001 | \
egrep '   Today |   Tonight ' -A 22 | awk 'BEGIN {print "\n\t\t\b\b\b\b\b\bTHE FIVE DAY\
WEATHER REPORT FOR THE NYC: 10001\n"} \
/[0-9][0-9]*[a-z|A-Z]+/{print $1"\t\t"$2" "$3"\t\t"$4" "$5"\n"}' 2>> error.txt

This gives no output.

share|improve this question
4  
The "small circle" is a degree symbol. –  user3463 Jan 21 '12 at 21:31
    
How do I awk that? –  userend Jan 21 '12 at 21:42
    
Looks like an awk-ward question. –  Mehrdad Jan 21 '12 at 23:35
add comment

2 Answers

up vote 1 down vote accepted

The easiest way is to use a dot to match the degree symbol.

/[0-9][0-9]*.[a-z|A-Z]+/

For example

$ echo -e "30\0260FHigh" \
| awk '/[0-9][0-9]*.[a-z|A-Z]+/ { print "yes" }'

yes

(\0260 is octal for the degree symbol in your question)

If you want to match it exactly you'd have to identify it's value in the encoding used. In the text in your question it seems to be 0xb0.

 $ echo -e "30\0260FHigh" \
 | awk '/[0-9][0-9]*\xb0[a-z|A-Z]+/ {print "yes" }'

 yes

\0260 and \xb0 just illustrate two ways to indicate the same thing.

share|improve this answer
    
Yes, this is what I needed. I guess my regex was off a bit. –  userend Jan 21 '12 at 22:26
add comment

Modern Linux shell is very Unicode-aware. In fact, I think all the data are treated as UTF-8.

I had no problem running this code:

$ echo ° | awk '/°/{print "found it"}'
found it

If you're making a shell script, make sure you have it in UTF-8 instead of ASCII.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.