Visit Our UNIX and Linux User Community


building text file with calendar dates


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting building text file with calendar dates
# 1  
Old 02-25-2002
builind text file with calendar dates

Can somebody help me in building a text file which will contain the dates of 2 yrs in the format YYYYMMDD using korn shell

e.g. to generate a file with the contents

20010101
20010102
...
...
20010131
20010201
...
...
20010228
20010301
...

and so on.
# 2  
Old 02-25-2002
Code:
#! /usr/bin/ksh

#              ja fe ma ap ma ju ju ag se oc no de
set -A lasts 0 31 28 31 30 31 30 31 31 30 31 30 31

typeset -Z2 dmonth dday

#
#  loop on years

year=2001
while ((year<2003)) ; do

#
#  is this a leap year?
        leap=0
        if ((!(year%100))); then
                ((!(year%400))) && leap=1
        else
                ((!(year%4))) && leap=1
        fi

#
#  set number of days in february
        lasts[2]=28
        ((leap)) && lasts[2]=29
#
#  loop on month
        month=1
        while ((month<13)); do

#
#  loop on day
                day=1
                while((day<(lasts[month])+1)) ; do
                        dday=$day 
                        dmonth=$month
                        echo ${year}${dmonth}${dday}
                        ((day=day+1))
                done
                ((month=month+1))
        done

        ((year=year+1))
done
exit 0

# 3  
Old 02-26-2002
Thanks Perderabo !

It has worked well.

Previous Thread | Next Thread
Test Your Knowledge in Computers #979
Difficulty: Medium
macOS is based on the Unix operating system and on technologies developed between 1985 and 1997 at NeXT.
True or False?

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Shell Programming and Scripting

Sum duplicate values in text file through awk between dates

I need to sum values in text file in case duplicate row are present with same name and different value below is example of data in file i have and format i need. Data in text file 20170308 PM,U,2 PM,U,113 PM,I,123 DA,U,135 DA,I,113 DA,I,1 20170309 PM,U,2 PM,U,1 PM,I,123 PM,I,1... (3 Replies)
Discussion started by: Adfire
3 Replies

3. Homework & Coursework Questions

Need help creating shell script with output that has 2014 calendar and 2 text items from a"fortune"

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am required to create a bash shell script with either emacs or vi. It must include the year 2014 calendar on... (9 Replies)
Discussion started by: dandanhelpmeman
9 Replies

4. UNIX for Dummies Questions & Answers

How to write the dates between 2 dates into a file

Hi All, I am trying to print the dates that falls between 2 date variables into a file. Here is the example. $BUS_DATE =20120616 $SUB_DATE=20120613 Output to file abc.txt should be : 20120613,20120614,120120615,20120616 Can you pls help me accomplish this in LINUX. Thanks... (5 Replies)
Discussion started by: dsfreddie
5 Replies

5. Shell Programming and Scripting

dealing with dates in a text file

hi guys im trying to write a bash script that grabs expired domain names it leaves me with the following outpiut in a text file Im hoping to try to normalise all the dates to the format displayed in the first 2 lines and remove the times so the file looks unfirom can any one give me a... (9 Replies)
Discussion started by: dunryc
9 Replies

6. Shell Programming and Scripting

Help with filtering dates from the calendar

Hi, I need a simple shell script to help filter weekends from the calendar of a month. In other words, i need a script to identify the working days in a month. (3 Replies)
Discussion started by: pravsripad
3 Replies

7. Shell Programming and Scripting

Reading text file and comparing the dates in Kshell

I have a text file in which holidays are listed as YYYYMMDD. Here is the sample data of the file. 20090911 20090912 20090913 I need to read this file and see if the current day is listed in this text file. If today and any of the rows in my text file match, I need to do further... (2 Replies)
Discussion started by: Pramodini Rode
2 Replies

8. Shell Programming and Scripting

Need script to generate all the dates in DDMMYY format between 2 dates

Hello friends, I am looking for a script or method that can display all the dates between any 2 given dates. Input: Date 1 290109 Date 2 010209 Output: 300109 310109 Please help me. Thanks. :):confused: (2 Replies)
Discussion started by: frozensmilz
2 Replies

Featured Tech Videos