Sponsored Content
Top Forums Shell Programming and Scripting how to increment days according to year & month Post 302391590 by daptal on Monday 1st of February 2010 11:47:01 PM
Old 02-02-2010
If you want to use perl

Code:
my @mon_array = (0,31,28,31,30,31,30,31,31,30,31,30,31);
my $leap = 0; # ==> not a leap year
open my $fh ,'<' , "abc.txt" || die "$!";
while(<$fh>){
        chomp;
        my @cols = split("\t");  # change to the delimiter if needed
        my $year = $cols[1];

        $leap = 1 if ((!($year % 100) && !($year % 400)) || (($year % 100) && !($year % 4)));
        my $num_of_days_from_prev_months = 0;
        for my $i (1 .. ($cols[2]-1)){
                $num_of_days_from_prev_months += ($i ==2 ) ? (($leap == 1) ? 29 : 28) : $mon_array[$i];
        }
        my $final_days = ($year-1900) * 365 + $num_of_days_from_prev_months + $cols[3];
        for(my $i=0;$i<=$#cols;$i++){
                ($i ==3) ? print "$final_days\t" : print "$cols[$i]\t";
        }
        print "\n";
}
close $fh;

HTH,
PL
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script for tar and zip based on month & year

Hi Friends, I'm doing on script which finds all the files with time stamp and makes them tar and zip, based on their respective month&year. for instance "mar-2004.tar.zip" will contain all the files which was created/accessed/modified on mar-2004. like this the entire filesystem should be taken... (1 Reply)
Discussion started by: tuxfello
1 Replies

2. UNIX for Advanced & Expert Users

how to get the last month and year in UNIX

how to get the last month and year in UNIx (2 Replies)
Discussion started by: Vijay06
2 Replies

3. Programming

Interval year to month

Hi, I'm working on a Informix4gl module. I'm just trying to find out any built-in function to fetch only the year/month from an INTERVAL YEAR TO MONTH data value. Please let me know, if there are any functions to do this. If not, let me know for any alternative solutions to attain this. ... (5 Replies)
Discussion started by: dvah
5 Replies

4. Shell Programming and Scripting

want to get last year and month from the file

Hi I have files like abc_cd_20110302_123423 abc_cd_ef_20110301_123423 abc_cd_ef_20110403_123423 abc_ef_20110401_123423 I want to extract the the year and month associated with each file. I tried logfileyearmonth=`echo $logfile | awk -F_'{print $NF}'` Any other way can I... (6 Replies)
Discussion started by: dgmm
6 Replies

5. UNIX for Dummies Questions & Answers

Simpler next month year program

I have created this program to get the next month and year. Is there a simpler way. #!/bin/ksh string=`cat Date.txt` year=`echo $string | cut -c 1-4` month=`echo $string | cut -c 5-6` echo $year$month mon=`expr $month + 1` if ; then mon=0$mon echo $mon fi if ; then month=01 ... (2 Replies)
Discussion started by: w020637
2 Replies

6. Shell Programming and Scripting

How to list files that are not first two files date & last file date for every month-year?

Hi All, I need to find all files other than first two files dates & last file date for month and month/year wise list. lets say there are following files in directory Mar 19 2012 c.txt Mar 19 2012 cc.txt Mar 21 2012 d.txt Mar 22 2012 f.txt Mar 24 2012 h.txt Mar 25 2012 w.txt Feb 12... (2 Replies)
Discussion started by: Makarand Dodmis
2 Replies

7. Shell Programming and Scripting

How to find all files for same month and year?

Hi All, I find all files for same month and year lets say there are following files in directory -rwxr-xr-x 1 user userg 1596 Mar 19 2012 c.txt -rwxr-xr-x 1 user userg 1596 Mar 21 2012 d.txt -rwxr-xr-x 1 user userg 1596 Mar 22 2012 f.txt -rwxr-xr-x 1... (8 Replies)
Discussion started by: Makarand Dodmis
8 Replies

8. Shell Programming and Scripting

How to find all files other than first two dates & last date per month and year?

how to find all files other than first two dates & last date per month and year Hi All, lets say there are following files in directory -rwxr-xr-x 1 user userg 1596 Mar 19 2012 a.txt -rwxr-xr-x 1 user userg 1596 Mar 19 2012 b.txt -rwxr-xr-x 1 user userg ... (6 Replies)
Discussion started by: Makarand Dodmis
6 Replies

9. UNIX for Beginners Questions & Answers

Best way to increment weeks based on fiscal start year

Hi Folks - I'm looking for the best way to to increment fiscal weeks - allow me to explain. At my one client, 10/01/17 was the beginning if year fiscal year 2018. Each week, I need to manage a unique set of variable that are updated in my application - they are called substitution variables.... (31 Replies)
Discussion started by: SIMMS7400
31 Replies
DateTime::LeapSecond(3) 				User Contributed Perl Documentation				   DateTime::LeapSecond(3)

NAME
DateTime::LeapSecond - leap seconds table and utilities VERSION
version 1.06 SYNOPSIS
use DateTime; use DateTime::LeapSecond; print "Leap seconds between years 1990 and 2000 are "; print DateTime::Leapsecond::leap_seconds( $utc_rd_2000 ) - DateTime::Leapsecond::leap_seconds( $utc_rd_1990 ); DESCRIPTION
This module is used to calculate leap seconds for a given Rata Die day. It is used when DateTime.pm cannot compile the XS version of this code. This library is known to be accurate for dates until December 2009. There are no leap seconds before 1972, because that's the year this system was implemented. o leap_seconds( $rd ) Returns the number of accumulated leap seconds for a given day, in the range 0 .. 22. o extra_seconds( $rd ) Returns the number of leap seconds for a given day, in the range -2 .. 2. o day_length( $rd ) Returns the number of seconds for a given day, in the range 86398 .. 86402. SEE ALSO
<http://hpiers.obspm.fr/eop-pc/earthor/utc/leapsecond.html> http://datetime.perl.org AUTHOR
Dave Rolsky <autarch@urth.org> COPYRIGHT AND LICENSE
This software is Copyright (c) 2013 by Dave Rolsky. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) perl v5.18.2 2017-10-06 DateTime::LeapSecond(3)
All times are GMT -4. The time now is 06:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy