Renaming of multiple files with current date

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renaming of multiple files with current date
# 1  
Old 08-12-2009
Renaming of multiple files with current date


I have a fixed 4 files in each different directory. The total 17 directories are there each one having 4 files inside it. I need rename all of them with current date. The files formates will be as below:



Could you please help me in this regards.

# 2  
Old 08-12-2009
Are ddmmyyy in the files having other dates?
if yes, Do you mean to want the current date in place of "ddmmyyyy" ??
# 3  
Old 08-12-2009

Last edited by clx; 08-12-2009 at 10:04 AM.. Reason: same thing posted twice: browser issue
# 4  
Old 08-15-2009
Using ksh something like
today=$(printf "%(%d%m%Y)T" now)

echo "$today"
# fix filegeneration if needed. My example has done in main directory and 
# those 17 directories are subdirectories
for f in */abc_???_???_????????.txt
       # parse line using delimeter _ and .
        echo "$f" | IFS="_." read part1 part2 part3 partdate end str
        partdate="$today"   # newdate value
        [ -f "$newname" ] && echo "$newname already exist" >&2 && continue
        # remove echo after you have tested
        echo mv "$f" "$newname"

# 5  
Old 08-15-2009
ls | while read file
	echo mv $file ${file%_*}_$(date +%_d%m%Y).${file#*.}

If you like the output remove the echo
# 6  
Old 08-18-2009
Yes...ddmmyyyy will be old date. I need to replace ddmmyyyy with current date for all the files.

Originally Posted by anchal_khare
Are ddmmyyy in the files having other dates?
if yes, Do you mean to want the current date in place of "ddmmyyyy" ??
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to replace a parameter(variable) date value inside a text files daily with current date?

Hello All, we what we call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to... (1 Reply)
Discussion started by: pradeepp
1 Replies

2. UNIX for Beginners Questions & Answers

UNIX script to replace old date with current date dynamically in multiple files present in a folder

I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server $ cat temp.txt RTG*888*TD8*20180201~... (1 Reply)
Discussion started by: Shankar455
1 Replies

3. Shell Programming and Scripting

Shell script to check current date file is created and with >0 kb or not for multiple directories

Hi All, I am new in scripting and working in a project where we have RSyslog servers over CentOS v7 and more than 200 network devices are sending logs to each RSyslog servers. For each network devices individual folders create on the name of the each network devices IP addresses.The main... (7 Replies)
Discussion started by: Pinaki
7 Replies

4. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

5. Shell Programming and Scripting

WHM Crontab and Folder Renaming to current date

Hello, i am trying to rename a folder named 'cpbackup' to current date in our WHM Root via setting up a cronetab entry. but the folder does not get renamed on the scheduled time :confused: */1 * * * * timestamp=$(date +%m%d%Y);/bin/mv /ac_backups/cpbackup /ac_backups/$timestamp (4 Replies)
Discussion started by: kandyjet
4 Replies

6. UNIX for Dummies Questions & Answers

Renaming Multiple files

Hello, I have multiple files that I want to change the names to. Let's say for example that I want to rename all the files in the left column to the names in the right column: What would be the easiest way to go about doing this? Thanks. (1 Reply)
Discussion started by: Scatterbrain26
1 Replies

7. Shell Programming and Scripting

renaming multiple files

I have to rename 100+ files at a time on the server & was trying to use a script for doing that. I have used ultra edit to create a file having current filename & new file name as below file234.txt | file956.txt file687.txt | file385.txt There is no fixed pattern while renaming & would... (20 Replies)
Discussion started by: crux123
20 Replies

8. Shell Programming and Scripting

Renaming multiple files

I have a bunch of files txt1.csv--2008 thru to txt3.csv--2008. If i wanted to rename these files all at the same time to txt*.csv-2008 what would be the best way to do it... Just need to get rid of the extra - in each file name.. not all files are going to be called txt*.csv--2008. Just... (6 Replies)
Discussion started by: Jazmania
6 Replies

9. Shell Programming and Scripting

Finding files older than the current date and time and renaming and moving

Hi, I have a very urgent requirement here. I have to find all files in the specified directory but not in the sub directories(The directory name is stored in a variable) which are older than the current date as well as current time and rename it as filename_yyyymmddhhmmss.ext and move it into a... (7 Replies)
Discussion started by: ragavhere
7 Replies

10. Shell Programming and Scripting

Renaming multiple files

Can someone please tell me how I can rename a bunch of files at a time. I hava a directory that has 700+ files that are named *.xyz and I would like to rename them to *.abc . How can I do that with a simple command ? mv *.xyz *.abc did not work. Thanks in advance (4 Replies)
Discussion started by: jxh461
4 Replies
Login or Register to Ask a Question