Script to set columns to days in month


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to set columns to days in month
# 1  
Old 12-11-2012
Script to set columns to days in month

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:

Code:
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.

Thanks.
# 2  
Old 12-11-2012
I didn't quite understand your requirements but if you have an input file with data, each line can be appended in the below way
Code:
while read LINE
do
    TODAY=`date "+%d%b%Y"`
    
    echo "$TODAY $LINE" >> $OPTPUT_FILE
    
done < $INPUT_FILE

# 3  
Old 12-11-2012
Not sure of purpose of missing data columns. An example script to start with:
Code:
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

# 4  
Old 12-11-2012
Not sure I understand either. Why do you have 41 cols for Jan and Feb when each col is a day of month?
Is the data file you present input or output?
# 5  
Old 12-11-2012
So each morning the previous days data is uploaded, replacing the -999.xx with actual data. So todays data file would look something like this:

Code:
Y2012M12   xx.xx       xx.xx        xx.xx   xx.xx        xx.xx        xx.xx   xx.xx       xx.xx       xx.xx        xx.xx  -999.xx   -999.xx   -999.xx   -999.xx   -999.xx   -999.xx   -999.xx   -999.xx   -999.xx   -999.xx   -999.xx   -999.xx   -999.xx   -999.xx   -999.xx   -999.xx   -999.xx   -999.xx   -999.xx   -999.xx   -999.xx

# 6  
Old 12-11-2012
So now -999.xx is missing data? In your first sample it was -999 indicating missing data.
# 7  
Old 12-11-2012
Quote:
Originally Posted by RudiC
So now -999.xx is missing data? In your first sample it was -999 indicating missing data.

Missing data is indicated with a -999.00
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Number of days in current month

I have a homework assignment: ---------------------------------------- "Display" the number of days in the current month. For example: September 1996 has 30 days ---------------------------------------- I am trying to just display the head of cal to start the sentence. eg. cal | head ... (1 Reply)
Discussion started by: eaafuddy
1 Replies

2. UNIX for Dummies Questions & Answers

Finding days in previous month

#!/bin/ksh day=1 month=1 year=2012 if then then prevmonth=31 elif then prevmonth=30 elif then then prevmonth=29 elif then prevmonth=29 else prevmonth=28 fi (4 Replies)
Discussion started by: vagar11
4 Replies

3. Shell Programming and Scripting

display number of days in current month

hi all searched google and here, cant find and am begining to suspect there is no options for this. shell = born with either the date or cal command I need to display the number of days in current month. can anyone point me in the right direction? (10 Replies)
Discussion started by: rontopia
10 Replies

4. Shell Programming and Scripting

Number of days in month from certain parameters

Hi, I have an issue in date processing, the issue is I have a month as an int ( 1 - 12 ), the weekday as int ( 0 - 6 , 0 = Sunday), and the week day in month as int ( 0 - 5, 5 = last ex: first sunday, last monday, third tuesday ... ), now from those three parameters is there a possible way to... (5 Replies)
Discussion started by: modn3
5 Replies

5. Shell Programming and Scripting

Number of days in the previous month

Hi all. I am scripting in a POSIX shell on HPUX. I am running a script that needs to determine the number of days in a month. I found this on the forum and it works great: X=`cal $(date +%m) $(date +%Y) | grep -v '' | wc -w` The issue is that I am running the script on the 7th day of... (11 Replies)
Discussion started by: lyoncc
11 Replies

6. Shell Programming and Scripting

How import $COLUMNS from set into script

im trying to do this inside a bash script; for ((a=$COLUMNS;a>0;a--)) do printf "=" done printf "\n" With it i want to display an "equals" line as long as de curent shell window. but i can't get the $COLUMNS variable from the set enviroment. Some help please. (2 Replies)
Discussion started by: Tártaro
2 Replies

7. Shell Programming and Scripting

calculate the number of days left in a month

does any one have any ideas how i would go about calculating the number of days left in the month from a bash script ?. I want to do some operations on a csv file according to the result (8 Replies)
Discussion started by: dunryc
8 Replies

8. UNIX for Dummies Questions & Answers

How do I set my date in a unix script to 'new month

Hi, I'm a newbie to unix and i'm loving every bit of it. I need assistance in setting my date function in my script to "new month". What I want to do is define the "newmonth" as the 1st of every month so my script can run by this time evry month through the year. Can someone assist. ... (1 Reply)
Discussion started by: Agent704
1 Replies

9. Shell Programming and Scripting

Calc number of days in a month

Looking for some help on capturing the number of days in a month to set as a loop counter. Any ideas, please let me know. (3 Replies)
Discussion started by: flounder
3 Replies

10. UNIX for Dummies Questions & Answers

Days of the month

Hello, Please can someone help me in getitng last 7 days from the current date? for eg: input /default : today (10/18/2004) required output: 10/17/2004 10/16/2004 10/15/2004 10/14/2004 10/13/2004 ... (6 Replies)
Discussion started by: Anamika
6 Replies
Login or Register to Ask a Question