×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

rename a mulitple file based with specific porting in a file name

rename a mulitple file based with specific porting in a file name

rename a mulitple file based with specific porting in a file name

(OP)
Dear team ,

I have a list of file name , I need to replace date which i have mentioned in the below files. the passing input is 20160101.

File

GE_AML_CUSTTADF_20160824.CSV
GE_AML_DAYSTSDF_20160824.CSV
GE_AML_DEPTTSDFS_20160824.CSV
GE_AML_SECMTSS_20160115.CSV


Need O/P

GE_AML_CUSTTADF_20160101.CSV
GE_AML_DAYSTSDF_20160101.CSV
GE_AML_DEPTTSDFS_20160101.CSV
GE_AML_SECMTSS_20160101.CSV

RE: rename a mulitple file based with specific porting in a file name

Hi

Such renaming is the simplest to do with the rename command from the File::Rename Perl package.

( Note that there is no standard rename command on Unix/Linux. Some distributions are shipping a rename command provided by the util-linux package, which has different syntax and is not helpful in this case. If you find no rename command on your machine, check also rename.pl as occasionally is shipped with that name. )

CODE --> command line

master # ls -1
GE_AML_CUSTTADF_20160824.CSV
GE_AML_DAYSTSDF_20160824.CSV
GE_AML_DEPTTSDFS_20160824.CSV
GE_AML_SECMTSS_20160115.CSV

master # rename.pl 's/\d{8}/20160101/' *.CSV

master # ls -1
GE_AML_CUSTTADF_20160101.CSV
GE_AML_DAYSTSDF_20160101.CSV
GE_AML_DEPTTSDFS_20160101.CSV
GE_AML_SECMTSS_20160101.CSV 
Assuming the only occurrence of 8 consecutive digits is in the date to be replaced.

In case you not have rename, you will have to use mv in a loop and involve the shell's capabilities to craft the new file names :

CODE --> Bash, Dash, Ksh, Yash, Zsh

for file in *.CSV; do mv "$file" "${file%_*}_20160101.${file##*.}"; done 
Assuming the date is always after the last underscore ( _ ) character.

In case you not have a Bourne shell compatible shell that understands the above command, pleas provide details about what you have.

Feherke.
feherke.ga

RE: rename a mulitple file based with specific porting in a file name

(OP)
Need one more help from above ques?.. how to extract date only in the file name.

Needed o/p..

20160824
20160115

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close