LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-14-2013, 02:27 AM   #1
annonyxxxx
Member
 
Registered: May 2013
Posts: 31

Rep: Reputation: 9
How to rename a part of a file or files


hey everybody in LQ

I have a few video files with this name structure.

TV Show Season 1 - Ep 1 title.mp4
TV Show Season 1 - Ep 2 title.mp4
TV Show Season 1 - Ep 3 title.mp4
etc..

I want to change it to this

TV Show Season 1 - Ep 01 title.mp4
TV Show Season 1 - Ep 02 title.mp4
TV Show Season 1 - Ep 03 title.mp4

What is the solution? thank you folks

Last edited by annonyxxxx; 05-14-2013 at 02:29 AM.
 
Old 05-14-2013, 02:32 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,643

Rep: Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501
How many files are there? Renaming a few can be done by hand...
 
Old 05-14-2013, 03:21 AM   #3
annonyxxxx
Member
 
Registered: May 2013
Posts: 31

Original Poster
Rep: Reputation: 9
I have 20 files but I want to change the first 9 files. So far I have been doing it manually but it gets tedious after a while.
 
Old 05-14-2013, 03:23 AM   #4
parnmatt
Member
 
Registered: Apr 2013
Location: Lancaster
Distribution: Mac OS X
Posts: 38

Rep: Reputation: 7
Create a for-in loop over all your *.mp4's
Replace the Ep 1 with Ep 01 etc.
Rename it.

In a file:
Code:
#!/bin/sh
for file in *.mp4; do
    renamedFile=$(echo $file | sed 's/Ep \([0-9]\)/Ep 0\1/')
    echo mv \"$file\" \"$renamedFile\" | sh
done
Or in one line from the Terminal:
Code:
for file in *.mp4; do echo mv \"$file\" \"$(echo $file | sed 's/Ep \([0-9]\)/Ep 0\1/')\" | sh; done

Last edited by parnmatt; 05-14-2013 at 03:31 AM. Reason: Code slight wrong; now fixed
 
Old 05-14-2013, 03:38 AM   #5
annonyxxxx
Member
 
Registered: May 2013
Posts: 31

Original Poster
Rep: Reputation: 9
you're the man parnmatt, it looks like freakin' algebra but it did the job
 
Old 05-14-2013, 03:45 AM   #6
parnmatt
Member
 
Registered: Apr 2013
Location: Lancaster
Distribution: Mac OS X
Posts: 38

Rep: Reputation: 7
You are most welcome.
Programming/Scripting kinda is a bit like maths.

Just remember to mark all helpful posts by clicking the Yes in the bottom corner of those posts.
And don't forget to mark the thread solved (at the top).
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Rename files using csv file and awk tuxlux Programming 6 09-03-2013 07:46 PM
how do you rename multiple files based on strings in a text file? Holering Programming 9 01-08-2013 10:22 PM
bash-code to rename files based on config file Yalla-One Programming 20 04-14-2010 01:39 PM
rename multiple file by moving part of the name to end of extension cashinke Linux - Newbie 1 08-26-2009 10:55 PM
Rename 100+ files from a text file AGazzaz Linux - Software 9 09-26-2008 12:41 AM


All times are GMT -5. The time now is 10:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration