Help in a Recursive date program!!!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in a Recursive date program!!!!
# 1  
Old 03-23-2007
Help in a Recursive date program!!!!

Hi,

I need a recursive program which when run appends todays date,month and year automatically to the existing file names..

I have aaa.txt file with some 90 odd file names.

aa.bb_cc
aa.bb_cc
.
.
.
aa.yy.zz

When the script is run for today,it should give me like..

aa.bb_cc.Mar-23-2007
aa.bb_cc.Mar-23-2007
.
.
.
aa.yy.zz..Mar-23-2007

and when the script is run for 2morrow,it should give me like

aa.bb_cc.Mar-24-2007
aa.bb_cc.Mar-24-2007
.
.
.
aa.yy.zz..Mar-24-2007

Or when the script has run for todays date,can we tell the script to automatically point to tomorrows date.Say after running Mar-23-2007,at the end it should point to Mar-24-2007.

Can anybody help me with this program....

Thanks for you help,
Kumar
# 2  
Old 03-23-2007
Run this script once to add that days date
Code:
dt=$( date "+%b-%d-%Y" )
for i in *
do
 mv $i ${i}".${dt}"
done

Once the file has date in it use this script
Code:
dt=$( date "+%b-%d-%Y" )
for i in *
do
 mv $i ${i%.*}".${dt}"
done

# 3  
Old 03-23-2007
If my understanding on your problem is correct, the below one will take filenames from aaa.txt and rename it with the date details..

Quote:
suffix=$(date +%d-%b-%Y)
while read line
do
{
mv $line $line$suffix
}
done<aaa.txt
# 4  
Old 03-23-2007
Quote:
Originally Posted by jacoden
If my understanding on your problem is correct, the below one will take filenames from aaa.txt and rename it with the date details..
When i execute this script..it gives me a error mesg saying...

./date.sh: syntax error at line 3: `suffix=$' unexpected

#!/usr/bin/sh

suffix=$(date+%d-%b-%y)
while read line
do
{
mv $line $line$suffix
}
done< /tmp/aaa/orig.txt
# 5  
Old 03-23-2007
Quote:
Originally Posted by anbu23
Run this script once to add that days date
Code:
dt=$( date "+%b-%d-%Y" )
for i in *
do
 mv $i ${i}".${dt}"
done

Once the file has date in it use this script
Code:
dt=$( date "+%b-%d-%Y" )
for i in *
do
 mv $i ${i%.*}".${dt}"
done

#!usr/bin/sh
#!/bin/tcsh

dt=$(date"+%b-%d-%y")

cd /tmp/aaa/

for i in *
do
mv $i ${i}".${dt}"
done

I get his error mesg when i execute the script..i dont know if i'm running it wrongly..

date1.sh: syntax error at line 4: `dt=$' unexpected
# 6  
Old 03-23-2007
I am not finding any errors...

Quote:
linux2alm:~/den> cat new.sh
suffix=$(date +%d-%b-%Y)
echo "Suffix is $suffix"
while read line
do
{
echo "Moving $line to $line$suffix"
#mv $line $line$suffix
}
done<aaa.txt

linux2alm:~/den> ./new.sh
Suffix is 23-Mar-2007
Moving aa.bb_cc to aa.bb_cc23-Mar-2007
Moving aa.vb_cc to aa.vb_cc23-Mar-2007
Moving aa.ob_cc to aa.ob_cc23-Mar-2007
Moving aa.ub_cc to aa.ub_cc23-Mar-2007
Moving aa.yb_cc to aa.yb_cc23-Mar-2007
Moving aa.fb_cc to aa.fb_cc23-Mar-2007
Moving aa.yy.zz to aa.yy.zz23-Mar-2007
# 7  
Old 03-23-2007
Quote:
Originally Posted by kumarsaravana_s
When i execute this script..it gives me a error mesg saying...

./date.sh: syntax error at line 3: `suffix=$' unexpected

#!/usr/bin/sh

suffix=$(date+%d-%b-%y)
That code would legal on Linux but illegal on Solaris. Which is one example of why you should mention your OS. On Solaris, sh really is sh, the old Bourne shell. On Linux, sh is a link to bash. You need to switch to a modern shell like bash or ksh.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk program date function no longer running

I work at a company that uses a program written in AWK to track various data and prepare reports. Worked with this program for three years plus (the author is no longer with us) and the YTD Production report will not return a report with a date after 123119. This is a problem. Below is the (I... (3 Replies)
Discussion started by: paulgdavitt
3 Replies

2. Shell Programming and Scripting

Converting a date to friday date and finding Min/Max date

Dear all, I have 2 questions. I have a file with many rows which has date of the format YYYYMMDD. 1. I need to change the date to that weeks friday date(Ex: 20120716(monday) to 20120720). Satuday/Sunday has to be changed to next week friday date too. 2. After converting the date to... (10 Replies)
Discussion started by: 2001.arun
10 Replies

3. Solaris

date command, loop/recursive

is it possible to use output of one date command as input of another? I would like to know the date of Monday two weeks ago. so, the idea is that one date command subtracts two weeks, and the other finds the Monday. (2 Replies)
Discussion started by: orange47
2 Replies

4. UNIX for Dummies Questions & Answers

Short Program for Checking Server date

Hi Guys, Good morning! I have a file which looks something like this: Command was launched from partition 0. ------------------------------------------------ Executing command in server server3 Thu Jan 12 11:10:39 EET 2012 ------------------------------------------------... (3 Replies)
Discussion started by: rymnd_12345
3 Replies

5. UNIX for Dummies Questions & Answers

Script to open program and send/execute command in program

Hi, i want to write a script that executes a program (exec?) . this program then requires a filename as input. how do i give it this input in the script so the program will be complete run and close by the script. e.g. exec prog.exe program then asks for filename "enter filename:"... (1 Reply)
Discussion started by: tuathan
1 Replies

6. Programming

date calculation program

Hi One of my vendor based tool is giving date in no. of days since 1900-01-01. So, I want to display in CCYYMMDD format. For ex:- Vendor based tool is giving as 38790 days since 1900-01-01 corresponding to12/sep/2006 Does anybody has the... (1 Reply)
Discussion started by: axes
1 Replies

7. UNIX for Advanced & Expert Users

find file with date and recursive search for a text

Hey Guyz I have a requirement something like this.. a part of file name, date of modification of that file and a text is entered as input. like Date : 080206 (MMDDYY format.) filename : hotel_rates text : Jim now the file hotel_rates.ZZZ.123 (creation date is Aug 02 2006) should be... (10 Replies)
Discussion started by: rosh0623
10 Replies

8. Programming

storing date into a file from a program

hi all: i want to store the current date in to a file from a program. every time i execute the prg the date should get appended into the file. help me plz (2 Replies)
Discussion started by: bankpro
2 Replies

9. Programming

may be simple but i don't know -- Print current date from C program

How to print current date of the Unix system accessing thru C++ program ? I wrote like this #include <time.h> ....... time_t tt; struct tm *tod; .... time(&tt); tod = localtime(&tt); cout << tod->tm_mon + 1 << "/" << tod->tm_mday << "/" ... (6 Replies)
Discussion started by: ls1429
6 Replies

10. UNIX for Advanced & Expert Users

date program in ksh

#Author : kkodava #!/usr/bin/ksh #Use of this program is You can findout the no of days & day of starting and ending dates #usage no_of_days startdate<yyyymmdd> enddate<yyyymmdd> syy=`echo $1|cut -c1-4` smm=`echo $1|cut -c5-6` sdd=`echo $1|cut -c7-8` eyy=`echo $2|cut -c1-4` emm=`echo... (1 Reply)
Discussion started by: krishna
1 Replies
Login or Register to Ask a Question