Jump to content



Photo

RENAME multiple files with different prefixes and suffix


  • Please log in to reply
2 replies to this topic

#1 1WayJonny

1WayJonny

    General, I salute you!

  • Joined: 05-May 05
  • Location: Dirty Jerzey

Posted 02 November 2012 - 13:44

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


#2 +Karl L.

Karl L.

    xorangekiller

  • Tech Issues Solved: 15
  • Joined: 24-January 09
  • Location: Virginia, USA
  • OS: Debian Testing

Posted 02 November 2012 - 22:42

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


#3 OP 1WayJonny

1WayJonny

    General, I salute you!

  • Joined: 05-May 05
  • Location: Dirty Jerzey

Posted 06 November 2012 - 02:26

Thanks for the help!



Click here to login or here to register to remove this ad, it's free!