#!/bin/bash # Starting with a cligen and an NOAA daily text file over the same date range # first file is cligen file # second file is NOAA daily text file # echo the cligen header to stdout cat ${1} | linex 1-15 # process cligen file to temporary file cat ${1} | sed 1,15d > file1.tmp # process NOAA daily text file to temporary file # extract date (break into fields in cligen order of day, month, year), precip, tmax, tmin # convert precip (inches) to (mm) # convert tmax, tmin (F) to (C) # Saint Paul cat ${2} | sed 1,2d | awk '{printf "%3i%3i%5i%6.1f%6.2f", substr($9,7,2), substr($9,5,2), substr($9,1,4), ($10 * 25.4), ($10*2.54); if ($10 > 0 ) printf "%5.2f%7.2f", (0.5), (15); if ($10 == 0) printf "%5.2f%7.2f", (0.0), (0.0); printf "%6.1f%6.1f\n", (($14 - 32) * 5 / 9), (($15-32) * 5 / 9)}' > file2.tmp # Lamberton cat ${2} | sed 1,2d | awk '{printf "%3i%3i%5i%6.1f%6.2f", substr($10,7,2), substr($10,5,2), substr($10,1,4), ($12 * 25.4), ($12*2.54); if ($12 > 0 ) printf "%5.2f%7.2f", (0.5), (15); if ($12 == 0) printf "%5.2f%7.2f", (0.0), (0.0); printf "%6.1f%6.1f\n", (($15 - 32) * 5 / 9), (($16-32) * 5 / 9)}' > file2.tmp # place two files side by side paste file2.tmp file1.tmp | awk '{printf "%s%s\n", substr($0,1,47), substr($0,95)}' rm file1.tmp file2.tmp