Need help to mass rename files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Need help to mass rename files
# 1  
Question Need help to mass rename files

Hi.

I've got 75 mp3s that have the word 'Émission' in their filename.

They are all in this format:

Émission bla1 bla1.mp3
Émission bla2 bla2.mp3
Émission bla3 bla3.mp3
etc...

I would just like to mass replace 'Émission' by 'Emission'; basically replace 'É' with 'E'. The rest of the filename should of course remain the same.

Thx
# 2  
Code:
$ touch "Émission bla1 bla1.mp3"
$ touch "Émission bla2 bla2.mp3"
$ touch "Émission bla3 bla3.mp3"
$ ls
Émission bla1 bla1.mp3	Émission bla2 bla2.mp3	Émission bla3 bla3.mp3
$ for i in *
do
mv "$i" "`echo $i | sed -e 's/É/E/g'`"
done
$ ls
Emission bla1 bla1.mp3	Emission bla2 bla2.mp3	Emission bla3 bla3.mp3
$

I suggest that you first _copy_ your Émission files into a separate directory and then run the script,
so that your other mp3's stay untouched.
If the renaming process worked, test your new files, if everything is okay, delete your old Émission files,
and move back your new files.

Enjoy!

Last edited by pseudocoder; 04-19-2010 at 05:08 PM.. Reason: added suggestion
# 3  
Alternatively, to replace the first character
Code:
for i in É* ; do 
  mv "$i" "E${i#?}"
done

To replace every character É with E (works in bash or ksh93)
Code:
for i in É* ; do 
  mv "$i" "${i//É/E}"
done

# 4  
Quote:
Originally Posted by pseudocoder
Code:
$ touch "Émission bla1 bla1.mp3"
$ touch "Émission bla2 bla2.mp3"
$ touch "Émission bla3 bla3.mp3"
$ ls
Émission bla1 bla1.mp3    Émission bla2 bla2.mp3    Émission bla3 bla3.mp3
$ for i in *
do
mv "$i" "`echo $i | sed -e 's/É/E/g'`"
done
$ ls
Emission bla1 bla1.mp3    Emission bla2 bla2.mp3    Emission bla3 bla3.mp3
$

I suggest that you first _copy_ your Émission files into a separate directory and then run the script,
so that your other mp3's stay untouched.
If the renaming process worked, test your new files, if everything is okay, delete your old Émission files,
and move back your new files.

Enjoy!
Thanks a lot! It effin worked. Only 1 second to do its deed... Sh really owns all these <expletive removed> software Smilie

---------- Post updated at 10:30 PM ---------- Previous update was at 10:09 PM ----------

OK so I've got a second question:

I have another folder of mp3s where the filenames have the following format:

001-actualsongname1.mp3
002-actualsongname2.mp3
003-actualsongname3.mp3

So now I would just like to remove the '00*-' part of the filename and only keep the 'actualsongname*.mp3' part.

Any tips? Smilie

edit by bakunin: Please! We are neither freaks nor script kiddies, so kindly adapt your language. We are professionals and we would like to be talked to that way. You might get just stony silence instead of help otherwise. Thank you for your consideration.

Last edited by bakunin; 04-19-2010 at 11:44 PM..
# 5  
Quote:
Originally Posted by Kingzy
001-actualsongname1.mp3
002-actualsongname2.mp3
003-actualsongname3.mp3

So now I would just like to remove the '00*-' part of the filename and only keep the 'actualsongname*.mp3' part.

Any tips? Smilie
The same way as the other replacement:

Code:
for file in [0-9][0-9][0-9]-* ; do 
  mv "$file" "${file#???-}"
done

I hope this helps.

bakunin
# 6  
Kingzy, you're welcome. Here's another solution for your second question:
Code:
$ mkdir testmp3
$ cd testmp3
$ touch 001-actualsongname1.mp3
$ touch 002-actualsongname2.mp3
$ touch 003-actualsongname3.mp3
$ ls
001-actualsongname1.mp3	002-actualsongname2.mp3	003-actualsongname3.mp3
$ 
$ for i in *
do
mv "$i" "`echo $i | cut -d "-" -f2`"
done
$
$ ls
actualsongname1.mp3	actualsongname2.mp3	actualsongname3.mp3
$

Again, run this in a directory, that contains only the 000-* files.
# 7  
Question Vanishing MP3s

Thanks everyone for your suggestions. They all worked, as far as the script itself is concerned, but I encountered one issue:

I've got like 6 folders (albums) from that same artist, with mp3s of the format I described (00*-actualsongname*.mp3).

Before running the script I make a backup folder with the mp3s I want to modify, where I'll run the script (as per pseudocoder's suggestion). When I compare the folders after running the script, I notice that there are fewer files in the backup folder than in the original one.

So there may be a chance that, in the filenames, after the '00*-' part, the rest of the filename is the same. Could it be the reason that some mp3s disappeared? I can't really know for sure as there are at least 150 mp3s in each original folder, which are sorted by filename i.e. '00*-'

Out of the 6 albums, there was only one where no mp3s disappeared.

Hope I was clear enough.
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #144
Difficulty: Easy
IEEE designed POSIX around the common structure of the major competing variants of the Unix system, publishing the first POSIX standard in 1988.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SBATCH trinity for multiple files and rename/move the output files

Hey guys, I have wrote the following script to apply a module named "trinity" on my files. (it takes two input files and spit a trinity.fasta as output) #!/bin/bash -l #SBATCH -p node #SBATCH -A <projectID> #SBATCH -n 16 #SBATCH -t 7-00:00:00 #SBATCH --mem=128GB #SBATCH --mail-type=ALL... (1 Reply)
Discussion started by: @man
1 Replies

2. Shell Programming and Scripting

Rename mass files with text from first line

I have a few hundred text files that are currently numbered files. I would like to rename each one with the text from the first line in the file. I would prefer this is perl script rather than a one liner as it wil be after many alterations to the file via an existing script. Any help would be... (1 Reply)
Discussion started by: GWhizz
1 Replies

3. Programming

Minor editing of mass HTML files

Hello, I'm manipulating a batch of about 2,000 HTML files. I just need to make some small changes, but to all the files at once. For example, I want to delete the lines that have "embed_music" in all the files, or change all instances of the word "Paragraph" to "Absatz". This is my... (2 Replies)
Discussion started by: pxalpine
2 Replies

4. Shell Programming and Scripting

mass renaming files with complex filenames

Hi, I've got files with names like this : _Some_Name_178_HD_.mp4 _Some_Name_-_496_Vost_SD_(720x400_XviD_MP3).avi Goffytofansub_Some name 483_HD.avi And iam trying to rename it with a regular pattern. My gola is this : Ep 178.mp4 Ep 496.avi Ep 483.avi I've tried using sed with... (8 Replies)
Discussion started by: VLaw
8 Replies

5. Windows & DOS: Issues & Discussions

Windows mass copy files with same name in differnt folders

I have files existing with same names in the folders with date as display below c:\2010-09-10 <==== folder arr1.jpg arr2.jpg arr3.jpg arr4.jpg c:\2010-09-09 <==== folder arr1.jpg arr2.jpg c:\2010-09-08 <==== folder arr2.jpg arr3.jpg arr4.jpg ... (5 Replies)
Discussion started by: jville
5 Replies

6. Shell Programming and Scripting

bash script to rename in mass

Basically, I have a huge amount of files (ripped audiobooks) that all have the same garbage in their filenames. I'm wondering how to go about writing a bash script to mass rename them. Example filenames as they stand now: The First CD - 1x01 - Title 1.mp3 The First CD - 1x02 - Title 2.mp3... (4 Replies)
Discussion started by: audiophile
4 Replies

7. AIX

VI questions : mass changes, mass delete and external insert

Is it possible in VI to do a global change but take the search patterns and the replacement patterns from an external file ? I have cases where I can have 100,200 or 300+ global changes to do. All the new records are inside a file and I must VI a work file to change all of them. Also, can... (1 Reply)
Discussion started by: Browser_ice
1 Replies

8. Shell Programming and Scripting

Mass Change content in all files

Hi, Are there any sample scripts to change content like file paths, profile paths etc., from test version to production , instead of changing one by one, i would like to pass the in file (prod version/Test version) to convert to test or prod verions. any help is appreciated!! ~R (1 Reply)
Discussion started by: terala
1 Replies

9. UNIX for Dummies Questions & Answers

Mass Copy/rename

Don't tell me DOS can do something UNIX can't do! I want to copy a number of files from one directory to another, and at the same time change the names. The name changes would be common, e.g., all files starting with the letter 'L' and ending in '30.NEW554', with the copied or new files also... (6 Replies)
Discussion started by: lwilsonFG
6 Replies

10. UNIX for Dummies Questions & Answers

Easy way to mass rename files?

Hi. What is the easiest way to rename a bunch of files? For example taking all files ending in ".php3" and rename them to end in ".php" I could write a script to do this, but there is probably an easier way... Thanks! (17 Replies)
Discussion started by: Thermopylae
17 Replies

Featured Tech Videos