Sign in to follow this  
Followers 0

3 posts in this topic

Posted

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

Posted

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

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

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

Share this post


Link to post
Share on other sites

Posted

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  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.