I am trying to figure out how to assign columns of a text file to the day of the month. The end result will be a way to determine when each day (column) is populated with data.
The data file are in the format of:
M1Y2012 x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
M2Y2012 x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
.....
M12Y2012 x x x x x x x x -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999
Where column 1 is the month and year and the rest of the columns in that line are the data, each column being a day of the month. -999 is missing data.
I am somewhat familiar with awk and sed. Any suggestions are appreciated.
Not sure of purpose of missing data columns. An example script to start with:
while read d x
do
cal $(echo $d |
awk -F"[A-Z]*" '{print $1,$2,$3}') | sed -n '3,$p' |
awk -v d=$d 'BEGIN {printf d" "}{$1=$1}{print $0" "} END {print "\n"}' ORS=
done < infile
So I was thinking of something a little different from what has been suggested here. I thought that I could use the environment variables:
setenv day `date +"%d"`
setenv pday `expr ${day} - 1`
After assigning a day for each set of columns, I was thinking of looking for the line with the current year month (Y2012M12). Then determine if the previous day or 2 days has data.