The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
addition in sh shell cfg UNIX for Dummies Questions & Answers 1 09-28-2008 03:53 PM
Simple addition, help. Bandit390 Shell Programming and Scripting 3 09-23-2008 02:46 PM
addition email-lalit Shell Programming and Scripting 2 08-06-2008 05:58 PM
Addition problem onlyroshni Shell Programming and Scripting 2 12-10-2007 02:11 PM
floating point addition ravi raj kumar Shell Programming and Scripting 8 12-22-2006 02:47 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-13-2008
ali560045's Avatar
ali560045 ali560045 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 328
date addition

i have a script called date_add.sh written in k_shell

My shell script requirement is that it accepts a date from the user in the format YYYY-MM-DD and then it shows all the 15 days later day availaible in the current year

if date accepted from user is 2008-10-13,then the o/p sholud be
2008-10-28
2008-11-12
2008-11-27
2008-12-12
2008-12-27
-----------------------------------------------------------------------

How to put this logic in a loop? Also how to convert Epoch days into format YYYY-MM-DD

Current_day=`perl -e 'print int(time/86400);'`--------------------16145

but the below command is not working

perl -e '@d=localtime ((stat(shift))[9]); printf "%4d-%02d-%02d\n", $d[5]+1900,$d[4]+1,$d[3]' Current_day

Last edited by ali560045; 10-13-2008 at 06:44 AM..
  #2 (permalink)  
Old 10-13-2008
ali560045's Avatar
ali560045 ali560045 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 328
help in date script

below my script . Actually in my script i m taking the current date and then adding 15 days to it.
--------------------------------------------------------------------------

#!/bin/ksh

Current_day=`perl -e 'print int(time);'`
echo $Current_day

count=0
count=`expr $Current_day + 1296000`
echo $count

perl -le 'print scalar localtime('"$count"');'

perl -e '@d=localtime ((stat(shift))[9]); printf "%4d-%02d-%02d\n", $d[5]+1900,$d[4]+1,$d[3]' '"$count"'
--------------------------------------------------------------------------

the last command that converts the $count value into format YYYY-MM-DD is not working . plz help me in this?
  #3 (permalink)  
Old 10-13-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,635
stat works on files, not epoch seconds.
  #4 (permalink)  
Old 10-13-2008
ali560045's Avatar
ali560045 ali560045 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 328
ok. so how to convert the value of the below command into the formay YYYY-MM-DD so i should get the o/p as 2008-10-28

perl -le 'print scalar localtime('"$count"');'
  #5 (permalink)  
Old 10-13-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,635
Code:
#!/bin/ksh
tictock()
{ 
perl -e '
 $now = time;
 $increment = 1296000;
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($now);
 $year += 1900;
 
 for($i=0, $thisyear = $year ; $thisyear==$year ; $i++)
 {
    printf ("%4d-%02d-%02d ", $year, $mon, $mday);
 	$incr=($increment * $i) + $now;
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($incr);
    $year += 1900;
    $mon += 1;
  
 }
 '
}

set -A arr $(tictock )
let i=0
while [[ $i -lt ${#arr[*]} ]]
do 
    print ${arr[i]}
    i=$(( i + 1))
done
  #6 (permalink)  
Old 10-13-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,305
Quote:
Originally Posted by ali560045 View Post
i have a script called date_add.sh written in k_shell

My shell script requirement is that it accepts a date from the user in the format YYYY-MM-DD and then it shows all the 15 days later day availaible in the current year

if date accepted from user is 2008-10-13,then the o/p sholud be
2008-10-28
2008-11-12
2008-11-27
2008-12-12
2008-12-27
-----------------------------------------------------------------------


Code:
. date-funcs
year=$( date +%Y )

_DATESHIFT=$1
while :
do
  _dateshift $_DATESHIFT 15
  [ ${_DATESHIFT%%-*} -ne $year ] && break
  printf "%s\n" "$_DATESHIFT"
done
The date-funcs library of shell functions is available at The Dating Game.
Sponsored Links
Closed Thread

Bookmarks

Tags
perl, perl shift, shift, shift perl

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 10:17 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0