Sign in to follow this  

RENAME multiple files with different prefixes and suffix

Recommended Posts

1WayJonny    26

Hey guys,

Just need some help on creating a batch command to replace specific text in the file name. What I need it to do is no matter the files name prefix or suffix it will replace "5555" with "6666". I have almost gotten there as I can identify any file with "5555" but its adds "6666" after the "5555" instead of replacing the "5555"

i.e. of what I need it to do

Data1 Data2 Data3 5555 Data4.file

Data1 Data2 5555 Data4 Data 5.file

Data1 5555 Data4.file

Data1 Data2 Data3 6666 Data4.file

Data1 Data2 6666 Data4 Data5.file

Data1 6666 Data4.file

I appreciate any help in the matter...

Share this post


Link to post
Share on other sites
Karl L.    275

If you're looking to replace text in files, that sounds like a job for sed. You could do that using the following command.


$ sed -i 's/5555/6666/g' 5555.txt
[/CODE]

If you want to rename [i]files[/i], which I think is what you're asking, try the following command instead.

[CODE]
$ for filename in *5555*; do mv "$filename" "$(echo $filename | sed 's/5555/6666/g')"; done
[/CODE]

Share this post


Link to post
Share on other sites
1WayJonny    26

Thanks for the help!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.