Sponsored Content
Full Discussion: Date Range in UNIX
Top Forums Shell Programming and Scripting Date Range in UNIX Post 302769126 by Yoda on Monday 11th of February 2013 09:26:47 AM
Old 02-11-2013
If you have GNU date
Code:
#!/bin/bash

DT1=$1
DT2=$2

E_DT1=$( date -d"$DT1" +"%s" )
E_DT2=$( date -d"$DT2" +"%s" )

while [ $E_DT1 -lt $E_DT2 ]
do
        printf "%s " $( date -d@"$E_DT1" +"%Y-%m-%d" )
        DT1=$( date -d"$DT1 +6 days" +"%Y-%m-%d" )
        E_DT1=$( date -d"$DT1" +"%s" )
        [[ $E_DT1 -le $E_DT2 ]] && printf "%s\n" $( date -d@"$E_DT1" +"%Y-%m-%d" ) || printf "%s\n" $( date -d@"$E_DT2" +"%Y-%m-%d" )
done

---------- Post updated at 08:26 ---------- Previous update was at 08:25 ----------

Here is the o/p
Code:
$ ./dtrange 2013-01-01 2013-05-05
2013-01-01 2013-01-07
2013-01-07 2013-01-13
2013-01-13 2013-01-19
2013-01-19 2013-01-25
2013-01-25 2013-01-31
2013-01-31 2013-02-06
2013-02-06 2013-02-12
2013-02-12 2013-02-18
2013-02-18 2013-02-24
2013-02-24 2013-03-02
2013-03-02 2013-03-08
2013-03-08 2013-03-14
2013-03-14 2013-03-20
2013-03-20 2013-03-26
2013-03-26 2013-04-01
2013-04-01 2013-04-07
2013-04-07 2013-04-13
2013-04-13 2013-04-19
2013-04-19 2013-04-25
2013-04-25 2013-05-01
2013-05-01 2013-05-05

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

cp only files in certain date range

hi all, I'm trying to do a cp only on files I created on a given day or within a certain date range. What's the best way to do this? Cheers, KL (1 Reply)
Discussion started by: ee7klt
1 Replies

2. Shell Programming and Scripting

automated ftp script from unix -date range of files

Hi , I need some help to finish my ftp script and i need to find the last one weeks of fles updated in the sepecific directory and see those end with Z and ftp them to my backup server. Any help is appreciated. Thanks, Ravi :) (1 Reply)
Discussion started by: koduri0475
1 Replies

3. Programming

automated ftp script from unix -date range of files

Hi , I need some help to finish my ftp script and i need to find the last one weeks of fles updated in the sepecific directory and see those end with Z and ftp them to my backup server. Any help is appreciated. Thanks, Ravi :) (1 Reply)
Discussion started by: koduri0475
1 Replies

4. UNIX for Advanced & Expert Users

automated ftp script from unix -date range of files

Hi , I need some help to finish my ftp script and i need to find the last one weeks of fles updated in the sepecific directory and see those end with Z and ftp them to my backup server. Any help is appreciated. Thanks, Ravi :) (1 Reply)
Discussion started by: koduri0475
1 Replies

5. Shell Programming and Scripting

Get date range between 2 date input

Hi Experts, I have files name report_20090416 report_20090417 report_20090418 report_20090420 report_20090421 I have 2 input from user From Date: 20090417 To Date: 20090420 and I need to grep only those line in between. Output should be report_20090417 report_20090418... (3 Replies)
Discussion started by: tanit
3 Replies

6. UNIX Desktop Questions & Answers

date range

I have a number of instances wher I need to run reports for the previous month and need to include the last months date range in the sql. I want to create a string which consists of the first and last dates of last month separated with an ' and ' ie for this month (Feb) I want it to say '01/01/10... (3 Replies)
Discussion started by: Niven
3 Replies

7. Shell Programming and Scripting

Date Range Problem

Hi All, I have a log file which has first few characters of every line as a timestamp. 2010-06-01 04:56:02,802 DEBUG {Thread-27} Some text message 2010-06-01 04:56:02,802 DEBUG {Thread-27} Some text message 2010-06-01 04:56:02,802 DEBUG {Thread-27} Some text message 2010-06-01... (7 Replies)
Discussion started by: nitin14341
7 Replies

8. Shell Programming and Scripting

Date listing in a date range

Solaris 10 ksh88 Sorry for re-hashing some of this, but I can't find a proper solution in the forums. Starting with /a/archive containing (on and on date formatted directories) 20060313 20080518 20100725 20121015 20060314 20080519 ... (1 Reply)
Discussion started by: moesplace
1 Replies

9. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt “2012-06-15 08:13" ! -newermt “2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

10. Shell Programming and Scripting

Date range

Dear all, how can I select in the file below only the files created between Aug 14 2014 and Feb 03 2015? EZA2284I -rw-r--r-- 1 30 8 356954 Aug 15 2014 file1 EZA2284I -rw-rw-r-- 1 30 8 251396 Feb 05 12:53 file2 EZA2284I -rw-rw-r-- 1 30 8 ... (3 Replies)
Discussion started by: simomuc
3 Replies
sh(1)							      General Commands Manual							     sh(1)

NAME
sh - Shell, the standard command language interpreter DESCRIPTION
[Tru64 UNIX] Tru64 UNIX provides two command interpreters with the name sh. The XCU5.0 and POSIX.2 compliant command interpreter sh is available in the file /usr/bin/posix/sh and is described in the sh(1p) reference page. The Bourne shell, historically known as sh, is available in the file /usr/bin/sh and is described in the sh(1b) reference page. [Tru64 UNIX] Your initial, or login, shell is determined by your entry in the file /etc/passwd. This file can be changed only by your sys- tem administrator. You must use whatever procedures are in place at your location to have this entry changed. [Tru64 UNIX] If available on your system, you may use the passwd -s or the chsh commands to change your login shell. Note This option is not available if your site manages passwords through the Network Information Service (NIS) facility. Check with your system administrator. [Tru64 UNIX] Subsequent shells spawned from the initial shell depend on the value in the environment variable BIN_SH. If this variable is set to xpg4, the POSIX shell is started. If this variable is set to svr4, an SVR4 compliant version of the shell is started. If this vari- able is unset, the Bourne shell is started. If this variable is set to any other value, an error is reported and the results are unpre- dictable. See the EXAMPLES section for information on setting this variable. NOTES
[Tru64 UNIX] With Tru64 UNIX Version 4.0 the Korn shell, /usr/bin/ksh is the same as the POSIX shell /usr/bin/posix/sh. RESTRICTIONS
[Tru64 UNIX] The file /etc/shells must include entries for both the POSIX shell /usr/bin/posix/sh and the Bourne shell, /usr/bin/sh. If this file is incorrect, see your system administrator. EXAMPLES
Using the Bourne, Korn, or POSIX shell, to set the variable BIN_SH to use the POSIX/ XCU5.0compliant shell, enter: BIN_SH=xpg4 export BIN_SH Using the Bourne, Korn, or POSIX shell, to set the variable BIN_SH to use the SVR4 compliant shell, enter: BIN_SH=svr4 export BIN_SH Using the Bourne, Korn, or POSIX shell, to unset the variable BIN_SH, enter: unset BIN_SH Using the C/ shell, to set the variable BIN_SH to use the POSIX/XCU5.0 compliant shell, enter: setenv BIN_SH xpg4 Using the C/ shell, to set the variable BIN_SH to use the SVR4 compliant shell, enter: setenv BIN_SH svr4 Using the C/ shell, to unset the variable BIN_SH, enter: unsetenv BIN_SH FILES
User profile. Contains user information, including the login shell name. Contains the names of available and permitted shells. SEE ALSO
Commands: csh(1), ksh(1), Bourne shell sh(1b), POSIX shell sh(1p), passwd(1) Files: passwd(4), shells(4) Standards: standards(5) sh(1)
All times are GMT -4. The time now is 02:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy