• 0

RENAME multiple files with different prefixes and suffix


Question

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...

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

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]

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.