check if these programs work or not

User Generated

z6nn6

Computer Science

Description

Hello 

please check if this program work 

also, is it separate programs or no 

metar.txt 

weather.txt 

weather_metar.txt

 weather_script.txt 

Unformatted Attachment Preview

#!/bin/bash # NOTE: # type the location of the file with the METAR report as argument ($1) printf "Report type: " egrep -o 'METAR|SPECI' $1 printf "Station: " egrep -o '\sK[A-Z]{3}\s' $1 day_of_month=$(( $(cat $1 | cut -c12-13) )) hour=$(( $(cat $1 | cut -c14-15) )) minute=$(( $(cat $1 | cut -c16-17) )) printf "Day of the month: %d\n" $day_of_month printf "Time: %d:%d UTC\n" $hour $minute auto=$(( $(egrep -o 'AUTO|COR' $1) )) if [ -n $auto ]; then printf "Report is " if [[ $auto == "AUTO" ]]; then printf "automated\n" else printf "corrected\n" fi fi wind=$(egrep -o '\s[0-9]{3,5}G?[0-9]?[0-9]?KT\s' $1) if [[ $wind =~ G ]]; then printf "Wind gusts: Direction= %s degrees, Speed: %s knots\n" ${wind:0:4} $ {wind:5:2} else printf "Wind: Direction = %s degrees, Speed: %s knots\n" ${wind:0:4} ${wind:4:2} fi variance=$(egrep -o '\s[0-9]{3}V[0-9]{3}\s' $1) if [[ $variance =~ .*V.* ]]; then if [[ ${wind:4:1} -eq 0 ]]; then if [[ ${wind:5:1} -le 6 ]]; then speed=$(( $(egrep -o '\sVRB[0-9]{1,2}\s' $1 | cut -c5-6) )) printf "Wind direction variable. Wind speed: %d Knots\n" $speed else printf "Wind direction is variable between %s and %s knots\n" ${wind:0:4} $ {wind:5:3} fi fi fi sm=$(( $(egrep -o '\s[0-9]+SM\s' $1 | egrep -o '[0-9]+') )) printf "Visibility: %d Statute Miles\n" $sm ts="$(egrep -o '\s[\+|\-]?TS\s' $1)" if [[ $ts =~ TS ]]; then if [[ $ts =~ \+ ]]; then printf "Heavy thunderstorms\n" elif [[ $ts =~ \- ]]; then printf "Light thunderstorms\n" else printf "Moderate thunderstorms\n" fi fi altimeter="$(egrep -o '\sA[0-9]+\s' $1 | egrep -o '[0-9]+')" printf "Altimeter: %d.%d inHg\n" ${altimeter:0:2} ${altimeter:2:2} skc="$(egrep -o '\sSKC[0-9]{3}\s' $1 | cut -c5-7)" if [[ $skc -ne 0 ]]; then printf "Sky clear through %s00 feet above sea level\n" $skc fi few="$(egrep -o '\sFEW[0-9]{3}\s' $1 | cut -c5-7)" if [[ $few -ne 0 ]]; then printf "Clouds: A few, at %s00 feet above sea level\n" $few fi sct="$(egrep -o '\sSCT[0-9]{3}\s' $1 | cut -c5-7)" if [[ $sct -ne 0 ]]; then printf "Clouds: Scattered, at %s00 feet above sea level\n" $sct fi bkn="$(egrep -o '\sBKN[0-9]{3}\s' $1 | cut -c5-7)" if [ -n $bkn ]; then printf "Clouds: Broken, at %s00 feet above sea level\n" $bkn fi ovc="$(egrep -o '\sOVC[0-9]{3}\s' $1 | cut -c5-7)" if [[ $ovc -ne 0 ]]; then printf "Clouds: Overcast, at %s00 feet above sea level\n" $ovc fi tcu=$(( $(egrep -o '\sTCU\s' $1) )) if [[ -n $ovc ]]; then printf "Towering cumulonimbus clouds.\n" $tcu fi cb=$(( $(egrep -o '\sCB\s' $1) )) if [[ $cb =~ CB ]]; then printf "Cumulonimbus clouds.\n" $cb fi # doesn't need extra parentheses sometimes? vertical=$(egrep -o '\sVV[0-9]+\s' $1) if [[ $vertical =~ VV ]]; then printf "Vertical visibility: %s00 feet\n" ${vertical:3:3} fi temperature=$(( $(egrep -o '\s[0-9]+\/[0-9]+\s' $1 | cut -c1-3) )) dew=$(( $(egrep -o '\s[0-9]+\/[0-9]+\s' $1 | cut -c5-7) )) printf "Temerature: %d degrees Celcius\n" $temperature printf "Dew Point: %d degrees Celcius\n" $dew #!/bin/bash printf "Report type: " egrep -o 'METAR|SPECI' metar.txt printf "Station: " egrep -o '\sK[A-Z]{3}\s' metar.txt day_of_month=$(( $(cat metar.txt | cut -c12-13) )) metar_hour_time=$(( $(cat metar.txt | cut -c14-15) )) metar_minute_time=$(( $(cat metar.txt | cut -c16-17) )) printf "Day of the month: %d\n" $day_of_month printf "Time: %d:%d UTC\n" $metar_hour_time $metar_minute_time auto_cor=$(( $(egrep -o 'AUTO|COR' metar.txt) )) if [ -n $auto_cor ]; then if [[ $auto_cor == "AUTO" ]]; then printf "Automated Report\n" else printf "Corrected Observation\n" fi fi wind=$(egrep -o '\s[0-9]{3,5}G?[0-9]?[0-9]?KT\s' metar.txt) if [[ $wind =~ .*G.* ]]; then printf "Wind gusts: Direction= %s degrees, Speed: %s knots\n" ${wind:0:4} $ {wind:5:2} else printf "Wind: Direction= %s degrees, Speed: %s knots\n" ${wind:0:4} ${wind:4:2} fi wind_var=$(egrep -o '\s[0-9]{3}V[0-9]{3}\s' metar.txt) if [[ $wind_var =~ .*V.* ]]; then if [[ ${wind:4:1} -eq 0 ]]; then if [[ ${wind:5:1} -le 6 ]]; then speed=$(( $(egrep -o '\sVRB[0-9]{1,2}\s' metar.txt | cut -c5-6) )) printf "Wind direction variable. Wind speed: %d Knots\n" $speed else printf "Wind direction is variable between %d and %d\n" ${wind_var:0:4} $ {wind_var:5:3} fi fi fi sm=$(( $(egrep -o '\s[0-9]+SM\s' metar.txt | egrep -o '[0-9]+') )) printf "Visibility: %d Statute Miles\n" $sm ts="$(egrep -o '\s[\+|\-]?TS\s' metar.txt)" if [[ $ts =~ TS ]]; then if [[ $ts =~ \+ ]]; then printf "Heavy thunderstorms\n" elif [[ $ts =~ \- ]]; then printf "Light thunderstorms\n" else printf "Moderate thunderstorms\n" fi fi altimeter="$(egrep -o '\sA[0-9]+\s' metar.txt | egrep -o '[0-9]+')" printf "Altimeter: %d.%d inHg\n" ${altimeter:0:2} ${altimeter:2:2} skc_clouds="$(egrep -o '\sSKC[0-9]{3}\s' metar.txt | cut -c5-7)" if [[ $skc_clouds -ne 0 ]]; then printf "Sky clear through %s00 feet above sea level\n" $skc_clouds fi few_clouds="$(egrep -o '\sFEW[0-9]{3}\s' metar.txt | cut -c5-7)" if [[ $few_clouds -ne 0 ]]; then printf "Clouds: A few, at %s00 feet above sea level\n" $few_clouds fi sct_clouds="$(egrep -o '\sSCT[0-9]{3}\s' metar.txt | cut -c5-7)" if [[ $sct_clouds -ne 0 ]]; then printf "Clouds: Scattered, at %s00 feet above sea level\n" $sct_clouds fi bkn_clouds="$(egrep -o '\sBKN[0-9]{3}\s' metar.txt | cut -c5-7)" if [ -n $bkn_clouds ]; then printf "Clouds: Broken, at %s00 feet above sea level\n" $bkn_clouds fi ovc_clouds="$(egrep -o '\sOVC[0-9]{3}\s' metar.txt | cut -c5-7)" if [[ $ovc_clouds -ne 0 ]]; then printf "Clouds: Overcast, at %s00 feet above sea level\n" $ovc_clouds fi temperature=$(( $(egrep -o '\s[0-9]+\/[0-9]+\s' metar.txt | cut -c1-3) )) dew=$(( $(egrep -o '\s[0-9]+\/[0-9]+\s' metar.txt | cut -c5-7) )) if [[ $temperature -ne 0 ]]; then printf "Temerature: %d degrees Celcius\n" $temperature fi if [[ $temperature -ne 0 ]]; then printf "Dew Point: %d degrees Celcius\n" $dew fi #!/bin/bash #METAR|SPECI K[ALPHA]{3} [DIGIT]{6}Z AUTO|COR #_____ FIXED ___________________________ Optional # # ## wind conditions #[DIGIT]{5}G[DIGIT]{2}KT [DIGIT]{3}V[DIGIT]{3} | VRB[DIGIT] #- req --- -- opt --- rq --------- opt ------### processing ### #1) read string, but if using math expansion, cut only digits #2) egrep (extended grep) with -o option returns only matched string (watch spaces with cut) #3) Add if/else logic to print correct message or no message if missing, or with optional branches #4) Add "Cloud cover" all categories #5) Add check and report for Thunder Storms and or rain (light/moderate/heavy) printf "Report type: " egrep -o 'METAR|SPECI' metar.txt printf "Station: " egrep -o '\sK[A-Z]{3}\s' metar.txt day_of_month=$(( $(cat metar.txt | cut -c12-13) )) timeHour=$(( $(cat metar.txt | cut -c14-15) )) timeMinute=$(( $(cat metar.txt | cut -c16-17) )) printf "Day of the month: %d\n" $day_of_month printf "Time: %d:%d UTC\n" $timeHour $timeMinute auto=$(( $(egrep -o 'AUTO|COR' metar.txt) )) if [ -n $auto ]; then printf "Report is %s\n" $auto fi wind=$(egrep -o '\s[0-9]{3,5}G?[0-9]?[0-9]?KT\s' metar.txt) if [[ $wind =~ G ]]; then printf "Wind gusts: Direction= %s degrees, Speed: %s knots\n" ${wind:0:4} $ {wind:5:2} else printf "Wind: Direction = %s degrees, Speed: %s knots\n" ${wind:0:4} ${wind:4:2} fi variance=$(egrep -o '\s[0-9]{3}V[0-9]{3}\s' metar.txt) if [[ $variance =~ .*V.* ]]; then if [[ ${wind:4:1} -eq 0 ]]; then if [[ ${wind:5:1} -le 6 ]]; then speed=$(( $(egrep -o '\sVRB[0-9]{1,2}\s' metar.txt | cut -c5-6) )) printf "Wind direction variable. Wind speed: %d Knots\n" $speed else printf "Wind direction variable between %s and %s knots\n" ${wind:0:4} $ {wind:5:3} fi fi fi storm="$(egrep -o '\s[\+|\-]?TS\s' metar.txt)" if [[ $storm =~ TS ]]; then if [[ $storm =~ \+ ]]; then printf "Heavy thunderstorms\n" elif [[ $storm =~ \- ]]; then printf "Light thunderstorms\n" else printf "Moderate thunderstorms\n" fi fi statutem=$(( $(egrep -o '\s[0-9]+SM\s' metar.txt | egrep -o '[0-9]+') )) if [[ $statutem -ne 0 ]]; then printf "Visibility: %d statute miles\n" $statutem fi altimeter="$(egrep -o '\sA[0-9]+\s' metar.txt | egrep -o '[0-9]+')" if [[ $altimeter -ne 0 ]]; then printf "Altimeter: %d.%d inHg\n" ${altimeter:0:2} ${altimeter:2:2} fi clearClouds="$(egrep -o '\sSKC[0-9]{3}\s' metar.txt | cut -c5-7)" if [[ $skc_clouds -ne 0 ]]; then printf "Clear sky: at %s00 feet above sea level\n" $clearClouds fi fewClouds="$(egrep -o '\sFEW[0-9]{3}\s' metar.txt | cut -c5-7)" if [[ $few_clouds -ne 0 ]]; then printf "Clouds: A few, at %s00 feet above sea level\n" $fewClouds fi sctClouds="$(egrep -o '\sSCT[0-9]{3}\s' metar.txt | cut -c5-7)" if [[ $sct_clouds -ne 0 ]]; then printf "Clouds: Scattered, at %s00 feet above sea level\n" $sctClouds fi bknClouds="$(egrep -o '\sBKN[0-9]{3}\s' metar.txt | cut -c5-7)" if [ -n $bkn_clouds ]; then printf "Clouds: Broken, at %s00 feet above sea level\n" $bknClouds fi ovcClouds="$(egrep -o '\sOVC[0-9]{3}\s' metar.txt | cut -c5-7)" if [[ $ovc_clouds -ne 0 ]]; then printf "Clouds: Overcast, at %s00 feet above sea level\n" $ovcClouds fi towering=$(( $(egrep -o '\sTCU\s' metar.txt) )) if [[ $towering -ne 0 ]]; then printf "Towering cumulonimbus\n" fi cumulonimbus=$(( $(egrep -o '\sCB\s' metar.txt) )) if [[ $cumulonimbus -ne 0 ]]; then printf "Cumulonimbus\n" fi vertical=$(( $(egrep -o '\sVV[0-9]+\s' metar.txt) )) if [[ $vertical -ne 0 ]]; then printf "Vertical visibility is %s00 feet\n" $vertical fi temperature=$(( $(egrep -o '\s[0-9]+\/[0-9]+\s' metar.txt | cut -c1-3) )) printf "Temerature is %d degrees celcius\n" $temperature dew=$(( $(egrep -o '\s[0-9]+\/[0-9]+\s' metar.txt | cut -c5-7) )) printf "Dew Point is %d degrees celcius\n" $dew #!/bin/bash printf "Report type: " egrep -o 'METAR|SPECI' $1 printf "Station: " egrep -o '\sK[A-Z]{3}\s' $1 day_of_month=$(( $(cat $1 | cut -c12-13) )) timeHour=$(( $(cat $1 | cut -c14-15) )) timeMinute=$(( $(cat $1 | cut -c16-17) )) printf "Day of the month: %d\n" $day_of_month printf "Time: %d:%d UTC\n" $timeHour $timeMinute #METAR|SPECI K[ALPHA]{3} [DIGIT]{6}Z AUTO|COR #_____ FIXED ___________________________ Optional # # ## wind conditions #[DIGIT]{5}G[DIGIT]{2}KT [DIGIT]{3}V[DIGIT]{3} | VRB[DIGIT] #- req --- -- opt --- rq --------- opt ------### processing ### #1) read string, but if using math expansion, cut only digits #2) egrep (extended grep) with -o option returns only matched string (watch spaces with cut) #3) Add if/else logic to print correct message or no message if missing, or with optional branches #4) Add "Cloud cover" all categories #5) Add check and report for Thunder Storms and or rain (light/moderate/heavy) auto=$(( $(egrep -o 'AUTO|COR' $1) )) printf "Report is %s\n" $auto wind=$(egrep -o '\s[0-9]{3,5}G?[0-9]?[0-9]?KT\s' $1) if [[ $wind =~ G ]]; then printf "Wind gust: direction= %s degrees, speed: %s knots\n" ${wind:0:4} $ {wind:5:2} else printf "Wind: direction = %s degrees, speed: %s knots\n" ${wind:0:4} ${wind:4:2} fi variable=$(egrep -o '\s[0-9]{3}V[0-9]{3}\s' $1) if [[ $variable =~ .*V.* ]]; then if [[ ${wind:5:1} -le 6 ]]; then speed=$(( $(egrep -o '\sVRB[0-9]{1,2}\s' $1 | cut -c5-6) )) printf "Wind direction variable. Wind speed: %d Knots\n" $speed else printf "Wind direction variable between %s and %s knots\n" ${wind:0:4} $ {wind:5:3} fi fi storm="$(egrep -o '\s[\+|\-]?TS\s' $1)" if [[ $storm =~ TS ]]; then if [[ $storm =~ \+ ]]; then printf "Heavy thunderstorms\n" elif [[ $storm =~ \- ]]; then printf "Light thunderstorms\n" else printf "Moderate thunderstorms\n" fi fi statute=$(( $(egrep -o '\s[0-9]+SM\s' $1 | egrep -o '[0-9]+') )) if [[ $statute -ne 0 ]]; then printf "Visibility: %d statute miles\n" $statute fi altimeter="$(egrep -o '\sA[0-9]+\s' $1 | egrep -o '[0-9]+')" if [[ $altimeter -ne 0 ]]; then printf "Altimeter: %d.%d inHg\n" ${altimeter:0:2} ${altimeter:2:2} fi clear_clouds="$(egrep -o '\sSKC[0-9]{3}\s' $1 | cut -c5-7)" if [[ $skc_clouds -ne 0 ]]; then printf "Clear sky: at %s hundred feet above sea level\n" $clear_clouds fi few_clouds="$(egrep -o '\sFEW[0-9]{3}\s' $1 | cut -c5-7)" if [[ $few_clouds -ne 0 ]]; then printf "Clouds: A few, at %s hundred feet above sea level\n" $few_clouds fi scattered_clouds="$(egrep -o '\sSCT[0-9]{3}\s' $1 | cut -c5-7)" if [[ $sct_clouds -ne 0 ]]; then printf "Clouds: Scattered, at %s hundred feet above sea level\n" $scattered_clouds fi broken_clouds="$(egrep -o '\sBKN[0-9]{3}\s' $1 | cut -c5-7)" if [ -n $bkn_clouds ]; then printf "Clouds: Broken, at %s hundred feet above sea level\n" $broken_clouds fi overcast_clouds="$(egrep -o '\sOVC[0-9]{3}\s' $1 | cut -c5-7)" if [[ $ovc_clouds -ne 0 ]]; then printf "Clouds: Overcast, at %s hundred feet above sea level\n" $overcast_clouds fi towering_cumulonimbus=$(( $(egrep -o '\sTCU\s' $1) )) if [[ $towering_cumulonimbus -ne 0 ]]; then printf "towering_cumulonimbus cumulonimbus\n" fi cumulonimbus=$(( $(egrep -o '\sCB\s' $1) )) if [[ $cumulonimbus -ne 0 ]]; then printf "Cumulonimbus\n" fi vertical=$(( $(egrep -o '\sVV[0-9]+\s' $1) )) if [[ $vertical -ne 0 ]]; then printf "Vertical visibility is %s hundred feet\n" $vertical fi temperature=$(( $(egrep -o '\s[0-9]+\/[0-9]+\s' $1 | cut -c1-3) )) printf "Temerature is %d degrees celcius\n" $temperature dew=$(( $(egrep -o '\s[0-9]+\/[0-9]+\s' $1 | cut -c5-7) )) printf "Dew Point is %d degrees celcius\n" $dew
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer


Anonymous
Just the thing I needed, saved me a lot of time.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags