In this assignment, you are asked to do reformat the all-caps text messages as they were distributed by the National Weather Service until May 10, 2016, when this format was finally retired.
These messages usually appeared something like
SPECIAL TROPICAL DISTURBANCE STATEMENT NWS TPC/NATIONAL HURRICANE CENTER MIAMI FL 845 AM EDT WED SEP 12 2007 SATELLITE AND NWS RADAR OBSERVATIONS INDICATE THAT THE AREA OF LOW PRESSURE IN THE NORTHWESTERN GULF OF MEXICO IS BECOMING BETTER ORGANIZED THIS MORNING. THIS SYSTEM COULD BECOME A TROPICAL DEPRESSION LATER TODAY...AND AN AIR FORCE RESERVE UNIT RECONNAISSANCE AIRCRAFT WILL INVESTIGATE THE AREA EARLY THIS AFTERNOON. THE LOW IS MOVING SLOWLY NORTH-NORTHWESTWARD...AND REGARDLESS OF WHETHER OR NOT IT BECOMES A TROPICAL CYCLONE...HEAVY RAINS ARE EXPECTED TO SPREAD ACROSS SOUTHEASTERN TEXAS AND LOUISIANA OVER THE NEXT COUPLE OF DAYS. FOR INFORMATION SPECIFIC TO YOUR AREA...PLEASE CONSULT STATEMENTS ISSUED BY YOUR LOCAL NWS FORECAST OFFICE. FORECASTER FRANKLIN
Your task is to write a shell script that accepts one of these messages and reformats it.
The Unix tools that your shell script may use are
You can use any built-ins that you like from bash, including such items as echo, iteration constructions, and variable assignment.
You may not use any other general programming language, such as C, Perl, Python, or even awk.
Specifications
Your program should look to see if there is an argument; if so, then it should assume that the argument is a file name and try to work on that file. If there is no file, it should assume that input is coming from standard input.
All output should go to standard out.
Please name your shell script NWS.sh.
The new file should be reformatted in the following manner:
[However, with respect to proper names, I recognize that this problem is non-deterministic, and you may spend as much (or as little) time as you like on the proper names problem. (Hint: to do this, you can create static (or even dynamic) data files that provide spelling hints.)]
For instance, the previous message could be reformatted to:
Special tropical disturbance statement NWS TPC/National Hurricane Center Miami FL 845 am EDT Wed Sep 12 2007 Satellite and NWS radar observations indicate that the area of low pressure in the northwestern Gulf of Mexico is becoming better organized this morning. This system could become a tropical depression later today...and an Air Force reserve unit reconnaissance aircraft will investigate the area early this afternoon. The low is moving slowly north-northwestward...and regardless of whether or not it becomes a tropical cyclone...heavy rains are expected to spread across southeastern Texas and Louisiana over the next couple of days. For information specific to your area...please consult statements issued by your local NWS forecast office. Forecaster Franklin
Here are a number of example input and output files that you can use for testing:
Sample Input File | Corresponding Sample Output File |
---|---|
advisory.txt | advisory.txt.out |
advisory.txt-2 | advisory.txt-2.out |
discussion.txt | discussion.txt.out |
outlook.txt | outlook.txt.out |
summary.txt | summary.txt.out |
technical_advisory.txt-2 | technical_advisory.txt-2.out |