Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-12-2012
stevemcd1990's Avatar
Registered User
 
Join Date: Jun 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Multiple file rename

hi im new to linux and was just wondering if some 1 could help me

i have folders with T.V. series in them and i would like to delete part of the filename

e.g.

(series name).s01e01.(episode name)
(series name).s01e02.(episode name)
(series name).s01e03.(episode name)
(series name).s01e04.(episode name)
(series name).s01e05.(episode name)

i would like them to be

s01e01.(episode name)
s01e02.(episode name)
s01e03.(episode name)
s01e04.(episode name)
s01e05.(episode name)
Sponsored Links
    #2  
Old 06-12-2012
Registered User
 
Join Date: May 2012
Posts: 58
Thanks: 5
Thanked 9 Times in 9 Posts

Code:
ls | sed 's/<series name>\.\(.*\)\.\(.*\)/\1.\2/g' | xargs -I% mv '<series name>'.% %

Sponsored Links
    #3  
Old 06-12-2012
Peasant's Avatar
Registered User
 
Join Date: Mar 2011
Posts: 509
Thanks: 14
Thanked 104 Times in 102 Posts
Here is my try as well for the entire operation :

Position yourself in working folder (series folder)

Code:
ls -1 *.avi  | sed 's/.*\([Ss][0-9]\{1,2\}[Ee][0-9]\{1,2\}\)\(.*\)/mv "&" "\1\2" /g' # | bash

If you are satisfied with the result pipe it to bash (remove the comment #)
It should work with spaces in filenames and any <series name>, condition is that it respects the format S num num E num num

Hope that helps
Regards
Peasant.
    #4  
Old 06-12-2012
alister alister is offline Forum Advisor  
Registered User
 
Join Date: Dec 2009
Posts: 2,593
Thanks: 122
Thanked 716 Times in 599 Posts
Quote:
Originally Posted by Peasant View Post

Code:
ls -1 *.avi  | sed 's/.*\([Ss][0-9]\{1,2\}[Ee][0-9]\{1,2\}\)\(.*\)/mv "&" "\1\2" /g' # | bash

... It should work with spaces in filenames and any <series name>, condition is that it respects the format S num num E num num
Although it's not likely, for completeness' sake I will point out that a series name with a double quote will break that script. A leading dash will as well, but that's even less likely in a television series name.

Since I'm picking nits, the -1 option is never necessary when piping. ls examines its stdout and if it's not the terminal (in this case it's a pipe) it always writes one filename per line.

Regards,
Alister
The Following User Says Thank You to alister For This Useful Post:
Peasant (06-12-2012)
Sponsored Links
    #5  
Old 06-12-2012
Peasant's Avatar
Registered User
 
Join Date: Mar 2011
Posts: 509
Thanks: 14
Thanked 104 Times in 102 Posts
Thanks for your information about -1

Considering sed, that's why i suggested the op to inspect the output before running it actually, since it's not a large quantity of files

I presume that quality of code to cover all variants (escape chars, double quotes etc.) would be somewhat bigger then one sed line.

Regards
Peasant.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Rename multiple file names in a directory hari001 Shell Programming and Scripting 4 05-22-2011 04:14 PM
For Loop To Rename Multiple Files Finds One Non-existant File Korn0474 UNIX for Dummies Questions & Answers 5 11-16-2010 06:41 PM
Rename multiple file from file listing yshahiac Shell Programming and Scripting 5 02-09-2009 03:42 PM
mv command to rename multiple files that retain some portion of the original file nam grimace15 Shell Programming and Scripting 4 12-21-2008 05:27 AM
Help with multiple file rename - change case of part of file name steve7 UNIX for Dummies Questions & Answers 7 06-30-2005 01:41 PM



All times are GMT -4. The time now is 09:52 PM.