Copying files with the latest date


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Copying files with the latest date
# 22  
Old 08-01-2005
Its /usr/bin/ksh ....
# 23  
Old 08-01-2005
Try running reborg's version of the script with the header (i.e. the first line) as

#! /usr/bin/ksh

vino
# 24  
Old 08-01-2005
either /bin/ksh or /usr/bin/ksh, /bin is a compatibility link on Solaris, though it is better to use /usr/bin/ksh as the link may be removed at some time in the future.

The only remaining thing I can think of is that is you execute the script as:

sh theSctipt.sh it will be interpreted in bourne, giving the error you are seeing.
# 25  
Old 08-02-2005
Hi,

Thanks for all your help. I am able to execute the shell with couple of minor changes.

MONTH=`date +%b`
YEAR=`date +%y`
mth=$MONTH | tr '[A-Z]' '[a-z]'

But the translate function is not working. It is echoing as blank.

One more thing I would like to mention is that even if what ever the date I am running the script, but the script has to copy the files which are having the maximum month & year of the file.

For e.g. if I run the script today and the files present are of may & june's files i.e. bas100e1_may05, bas100e1_jun05. Then I have to copy bas100e1_jun05 to bas100e1. Can this be possible?

Thanks
Shash
# 26  
Old 08-02-2005
Quote:
Originally Posted by shashi_kiran_v
mth=$MONTH | tr '[A-Z]' '[a-z]'

But the translate function is not working. It is echoing as blank.
Since the back ticks work, try this.

Code:
mth=`echo $MONTH | tr '[A-Z]' '[a-z]'`

Quote:
Originally Posted by shashi_kiran_v
For e.g. if I run the script today and the files present are of may & june's files i.e. bas100e1_may05, bas100e1_jun05. Then I have to copy bas100e1_jun05 to bas100e1. Can this be possible?
Certainly.

Tho it requires more scripting.

Vino
# 27  
Old 08-02-2005
Hi Vino,

Thank you very much. It worked....

But can you help me with my previous query...
Can you please help me with the script.

Thanks
Shash
# 28  
Old 08-02-2005
How about this ?

Code:
#! /usr/bin/ksh

YEAR=`date +%y`
month="dec nov oct sep aug jul jun may apr mar feb jan"
for mon in $month
do
file=`ls *"$mon"* 2>/dev/null`
FILE=${file%%_$mon$YEAR}
cp $file $FILE
done

It assumes all the files of type bas100e1_xxx05 will end in 05, i.e. a 2005 file.

It actually came out much easier than I had thought it would be. Smilie

Vino
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl : copying only the latest file to other directory

In linux.. In a directory there are 3 files which I want to copy only the latest file (ls -ltr myfiles*.txt|tail -1) to other directory in perl? Could anyone please help me with the code? Regards, J (1 Reply)
Discussion started by: scriptscript
1 Replies

2. UNIX for Dummies Questions & Answers

Selecting the file of latest Date

Hi Folks, I have one query that there is a folder in which daily several logs files are getting created , I reached to that location through putty but what I observer that 10 files of different date are been created with same name , what I need to see is the latest file ...let say the location is ... (5 Replies)
Discussion started by: KAREENA18
5 Replies

3. UNIX for Dummies Questions & Answers

latest files copying over to new path

ls -lrt | nawk -v D="$(date +'%b%e:'| sed 's/ //g')" 'D==$6$7":"{sub(".*"$9,$9);print}' This picks only the latest files created based on the timestamp for that particular day.. how do i copy over the same files to a different location???? (1 Reply)
Discussion started by: win4luv
1 Replies

4. Shell Programming and Scripting

How to backup latest date files?

Hi, I have below two situations to handle, 1. I have list of files with file names having date&time. I have to backup to old date files. say I have below files in a directory, 1. XX123_20101004010101.dat 2. XX124_20101004010201.dat 3. XX121_20101003010101.dat 4.... (6 Replies)
Discussion started by: smr_rashmy
6 Replies

5. Shell Programming and Scripting

Copying a directory structure with the latest versions of files

Hello I have three directory structures for code releases. Each directory structure looks like this: bash-3.00$ ls -R | more .: Test_Release_1 Test_Release_2 Test_Release_3 ./Test_Release_1/dbcode: rp_online_import_srdp.pkb-1 srdp_ar_validation.pkb-1... (1 Reply)
Discussion started by: Glyn_Mo
1 Replies

6. Shell Programming and Scripting

Copying latest file into a folder

Hello all, this is my first post while i am trying to understand unix. I would basically like to know if i can do this: Lets say i have a folderA and folderB And i save something in folderA Can i make a script that checks folderA latest file, then compares it with the date of latest file in... (16 Replies)
Discussion started by: takissd
16 Replies

7. Shell Programming and Scripting

shell script to find latest date and time of the files

Hi everyone, Please help:) I have a list of 1000 different files which comes daily to the directory.Some of the files are not coming to the directory now. I need to write a shell script to find the latest date and time of the files they came to the directory. The files should be unique.... (1 Reply)
Discussion started by: karthicss
1 Replies

8. Shell Programming and Scripting

copying the latest file

Hi, I have a problem. I have some text files in a folder. The names can be like: emp_20080307053015.dat emp_20080306053015.dat emp_20080305053015.dat emp_20080304053015.dat The date format appended is like yyyymmdd and timestamp. What i need is i have to copy the latest file every... (12 Replies)
Discussion started by: Aswarth
12 Replies

9. Shell Programming and Scripting

Loop through files in dir, omit file with latest date

I want to loop through files in a directory but omit the file with the latest date in my list of files. How would I accomplish this? Thanks (2 Replies)
Discussion started by: stringzz
2 Replies

10. Shell Programming and Scripting

Copying files created after a specified date/time

I need to write a script that copies files from one directory to another that were created after "today 6:30". This script will be NOT be ran at the same time each day. any help is appreciated. (2 Replies)
Discussion started by: jm6601
2 Replies
Login or Register to Ask a Question