The UNIX and Linux Forums  

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
date calculation program axes High Level Programming 1 09-12-2006 11:11 PM
find file with date and recursive search for a text rosh0623 UNIX for Advanced & Expert Users 10 08-16-2006 03:27 PM
storing date into a file from a program bankpro High Level Programming 2 01-17-2006 05:28 AM
may be simple but i don't know -- Print current date from C program ls1429 High Level Programming 6 02-19-2002 01:50 AM
date program in ksh krishna UNIX for Advanced & Expert Users 1 08-30-2001 01:43 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-23-2007
kumarsaravana_s kumarsaravana_s is offline
Registered User
  
 

Join Date: Feb 2007
Location: Bangalore
Posts: 105
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 (permalink)  
Old 03-23-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
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 (permalink)  
Old 03-23-2007
dennis.jacob dennis.jacob is offline Forum Advisor  
dj - the student
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 611
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 (permalink)  
Old 03-23-2007
kumarsaravana_s kumarsaravana_s is offline
Registered User
  
 

Join Date: Feb 2007
Location: Bangalore
Posts: 105
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 (permalink)  
Old 03-23-2007
dennis.jacob dennis.jacob is offline Forum Advisor  
dj - the student
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 611
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
  #6 (permalink)  
Old 03-23-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
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.
  #7 (permalink)  
Old 03-23-2007
kumarsaravana_s kumarsaravana_s is offline
Registered User
  
 

Join Date: Feb 2007
Location: Bangalore
Posts: 105
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
Closed Thread

Bookmarks

Tags
linux

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 05:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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