create a series of regular expressions that identify different parts composing a METAR.
METARs are reports assembled with a particular format that is easy to decode with computer systems using regular expressions.
These reports typically come in two forms: North American METARs and International METARs. Create a series of regular expressions that decode each token of information using the North American METAR form.
You can find METAR reports at the following address:
In order to find the weather information you need to get a METAR report from any airport you wish utilizing the appropriate code and then apply the different regular expressions to identify each token and eventually extract it from the report.
submission should be a script that reads a single line METAR from a file named: metar.txt
Your script output (to the shell screen) should include:
1. the report type: either METAR or SPECI for “Special Report”
2. the station identifies (four characters starting with a K)
3. Day of the month and time the report was filed
4. If the token ‘AUTO’ is present, you should output “This is a fully automated report”
5. If the token ‘COR’ is present, you should output “This is a corrected observation”
6. Wind direction and speed, wind gusting, and variable wind directions
7. Visibility in statute miles
8. Light, medium, or heavy rain (-RA|RA|+RA)
9. Cloud Conditions: [0 or more occurrences of each of the following]
a. Sky Clear
b. Few Clouds <altitude>
c. Scattered Clouds <altitude>
d. Broken Clouds <altitude>
e. Overcast Clouds <altitude>
10. Temperature
11. Dew Point
12. Barometric Pressure
13. If the token ‘TH’ is present, you should output “Thunderstorms reported in the area”um temperature for past 6 hours reported to nearest tenth of degree Celsius; reported on 00, 06, 12, 18 UTC reports; sn = 1 if temperature below 0oC and 0 if temperature 0oC or higher.
the script that needs to be fixed:
#!/bin/bash
token1=”AUTO”
token2=”COR”
METARFILE=”metar.txt”
VSM=$(egrep -o ‘\s[[:digit:]]*SM’ $METARFILE | tr -d SM)
RAIN=$(egrep -o ‘?\WRA’ $METARFILE | tr -d [:blank:])
CLOUD_SKC=$((`egrep –o ‘SKC[[:digit:]]*?’ $METARFILE | cut -c4-6`*100))
CLOUD_FEW=$((`egrep –o ‘FEW[[:digit:]]*?’ $METARFILE | cut -c4-6`*100))
CLOUD_SCT=$((`egrep –o ‘SCT[[:digit:]]*?’ $METARFILE | cut -c4-6`*100))
CLOUD_BKN=$((`egrep –o ‘BKN[[:digit:]]*?’ $METARFILE | cut -c4-6`*100))
CLOUD_OVC=$((`egrep –o ‘OVC[[:digit:]]*?’ $METARFILE | cut -c4-6`*100))
TD_TEMP=$(egrep -o ‘[[:digit:]]{2}//?M[[:digit:]]{2}’ $METARFILE | cut -c1-2)
TD_DEW=$(egrep -o ‘[[:digit:]]{2}//?M[[:digit:]]{2}’ $METARFILE | tr -d M | cut -c4 5)
TH=$(egrep -o ‘\sTH\s’ $METARFILE | tr -d [:blank:] )
printf “Report type:\t\t”
egrep -o ‘METAR|SPECI’ $METARFILE
printf “Location:\t\t”
egrep -o ‘\sK[A-Z]{3}\s’ $METARFILE
DTGROUP=$(egrep -o ‘[[:digit:]]*Z’ $METARFILE)
day_of_month=$(echo $DTGROUP | cut -c1-2)
report_time_hour=$(echo $DTGROUP | cut -c3-4)
report_time_min=$(echo $DTGROUP | cut -c5-6)
printf “Day of month:\t\t%d\n” $day_of_month
printf “Time:\t\t\t%d:%d\n” $report_time_hour $report_time_min
wind=$(egrep -o ‘[[:digit:]]*?G[[:digit:]]*KT’ $METARFILE)
wind_dir=$(echo $wind | cut -c1-3)
wind_spd=$(echo $wind | cut -c4-5)
wind_var=$(egrep -o ‘\s[[:digit:]]V[[:digit:]]\s’ $METARFILE)
wind_var1=$(echo $wind_var | cut -c1-3)
wind_var2=$(echo $wind_var | cut -c5-7)
printf “Wind direction:\t\t%d, Speed: %d\n” $wind_dir $wind_spd
if [ “x$wind_var” != “x” ] ; then
printf “Wind direction is variable between %d and %d\n” $wind_var1
$wind_var2
fi
printf “Visibility:\t\t%d Status Miles\n” $VSM
if [ “$RAIN” == “+RA” ] ; then
printf “Heavy Rain\n”
elif [ “$RAIN” == “RA” ] ; then
printf “Medium Rain\n”
elif [ “$RAIN” == “-RA” ] ; then
printf “Light Rain\n”
else
printf “\n”
fi
printf “Cloud Conditions:\t\t\n”
[ $CLOUD_SKC ] && printf “Clouds: \t\tSky clear, at %d feet above sea level\n”
$CLOUD_SKC
[ $CLOUD_FEW ] && printf $CLOUD_FEW
[ $CLOUD_SCT ] && printf
$CLOUD_SCT
[ $CLOUD_BKN ] && printf
level\n” $CLOUD_BKN
[ $CLOUD_OVC ] && printf
level\n” $CLOUD_BKN
“Clouds: \t\tA few, at %d feet above sea level\n”
“Clouds: \t\tScattered, at %d feet above sea level\n”
“Clouds: \t\tBroken clouds, at %d feet above sea
“Clouds: \t\tOvercast clouds, at %d feet above sea
printf “Temperature:\t\t%s degrees Celsius\n” $TD_TEMP
printf “Dew point:\t\t%s degrees Celsius\n” $TD_DEW
if [ “$TH” ] ; then
printf “Thunderstorms reported in the area\n”
fi
if [ $(egrep -o “$token1\>” $METARFILE) ] ; then
printf “This is a fully automated report\n”
fi
if [ $(egrep -o “$token2\>” $METARFILE) ] ; then
printf “This is a corrected observation\n”
fi