Move Multiple Files adding date timestamp before file type


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Move Multiple Files adding date timestamp before file type
# 8  
Old 05-24-2013
Quote:
Originally Posted by Don Cragun
Not quite. The first time through this loop with the sample data specified by the OP would try to move /Data/Data/abc.csv to /archive/Data/abc_timestamp.csv
My bad, I didn't test the script. Yes, that's right, Don Cragun. Thanks for pointing it out, it would indeed consider /Data/Data/abc.csv.

Below is what I had in mind and the previous untested script does otherwise:
Code:
dt=$(date +%Y%m%d%H%M%S)
for file in /Data/*.csv
do
    file_ext=${file##*/}
    filename=${file_ext%.*}
    mv $file /archive/${filename}_${dt}.csv
done

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find file type recursively and move

Hello, I supposed that it was working fine but now I see that it's not working as expected. I am running under ubuntu14.04, trusty. My plan was to search folderA and all subdirectories and move any txt file to destination folder, folderB : find /home/user/folderA/ -type f -iname "*.txt"... (0 Replies)
Discussion started by: baris35
0 Replies

2. Shell Programming and Scripting

Move multiple files 4rm Source to different target folders based on a series num in the file content

Dear Experts my scenario is as follows... I have one source folder "Source" and 2 target folders "Target_123456" & "Target_789101". I have 2 series of files. 123456 series and 789101 series. Each series has got 3 types of fiels "Debit", "Refund", "Claims". All files are getting... (17 Replies)
Discussion started by: phani333
17 Replies

3. Shell Programming and Scripting

Sort and move multiple files by modification date

Hi I have a problem, I have a large group of archive files in a folder some are later versions of the same archive, the only difference btween them is that the archiving program we use appends the name with a code for it to keep track of in its data base, and the modification date. I am starting... (6 Replies)
Discussion started by: Paul Walker
6 Replies

4. Shell Programming and Scripting

Adding filename and line number from multiple files to final file

Hi all, I have 20 files (file001.txt upto file020.txt) and I want to read them from 3rd line upto end of file (line 1002). But in the final file they should appear to start from line 1. I need following kind of output in a single file: Filename Line number 2ndcolumn 4thcolumn I... (14 Replies)
Discussion started by: bioinfo
14 Replies

5. UNIX for Dummies Questions & Answers

Move Command with Adding Yesterday date

How to move a file with mv command by adding yesteday's date(YYYYMMDD) at the end Example: /a/abc.txt should be moved to the same folder /a/abc_yyyymmdd.txt YYYYMMDD should be yesterday's date (2 Replies)
Discussion started by: eskay
2 Replies

6. Shell Programming and Scripting

Check if a date field has date or timestamp or date&timestamp

Hi, In a field, I should receive the date with time stamp in a particular field. But sometimes the vendor sends just the date or the timestamp or correctl the date&timestamp. I have to figure out the the data is a date or time stamp or date&timestamp. If it is date then append "<space>00:00:00"... (1 Reply)
Discussion started by: machomaddy
1 Replies

7. Shell Programming and Scripting

write to multiple files depending on file type (solved)

I want a script that will add comments to a file before check-in files. comments depend on type of files. i have a script to list files in the directory that will be checked-in There are xml, js, html, vm files. vm will use comments like c/c++ ( // or /*..*/) can you help me add a comment line... (0 Replies)
Discussion started by: pradeepmacha
0 Replies

8. Shell Programming and Scripting

Adding timestamp to all inbound files

hi, can someone give me a sample shell scripts to make all inbound files will a have a Moveit timestamp.I think MoveIt is a server,thanks. (5 Replies)
Discussion started by: sonja
5 Replies

9. UNIX for Dummies Questions & Answers

UNIX command: mv - Objective: move files based on timestamp

I was wondering if there was a command to move files from one directory to another subdirectory based on the timestamp, i.e. moving from directory A files that have a timestamp of before the year 2005 into directory B. Directory B is a subdirectory located in directory A. I was advised to... (4 Replies)
Discussion started by: HLee1981
4 Replies

10. UNIX for Dummies Questions & Answers

move file change timestamp

Hello, Alright solution: I need to move files to a backup folder, changing the datestamp to the current day so that the file stays in the backup folder for the full 30 days before another script removes it. Obviously, any file I move in will preserve the timestamp which is what I *don't* want.... (2 Replies)
Discussion started by: tekster757
2 Replies
Login or Register to Ask a Question