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.
I would tend to parameterize it a little bit more with something like:
I usually use the Korn shell, but this will work with recent versions of ksh and bash without change. It defaults to /Data and /archive as the source and target directories but they can be overridden by supplying (absolute or relative) directory names as command line arguments. It also protects itself in case any of the components of the source and target files contain whitespace characters by quoting user supplied data. Production code should also verify that the cd succeeds and that all of the mv commands succeed.
But, now that I see that the OP has changed the requirements, this is obviously overkill. You could create a shell script using sed and write it as a 1-liner, write an awk script that invokes the shell to get the date and perform the moves, or convert a corrected shell script to a 1-liner but I won't help you play that game. I will always go for a readable, more easily maintainable script than a hard to read 1-liner.
This User Gave Thanks to Don Cragun For This Post:
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)
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)
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)
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×tamp. I have to figure out the the data is a date or time stamp or date×tamp.
If it is date then append "<space>00:00:00"... (1 Reply)
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)
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)
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)
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)
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)