LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 01-06-2013, 06:42 AM   #1
Adol
Member
 
Registered: Feb 2011
Location: Osaka, Japan
Distribution: Gentoo, Opensuse
Posts: 271

Rep: Reputation: 6
trying to change part of text with sequence for filename


Hello,

I have many files from when I made my tv show collection, but the way I made it is not compatible with the program Im using to get information for it.

For example I saved it as:
Code:
NameOfShow Episode 01 NameOfEpisode
I want to change Episode 01 to 1x1.

The problem is that I have many shows(MASH) and changing them one by one will take way too long.

I could change them easily using Dolphin but then I loose the Name of Episode.

How can I change the name while keeping NameOfShow and NameOfEpisode and have it automaticaly count up(1x1,1x2,1x3,etc)?
 
Old 01-06-2013, 07:55 AM   #2
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,376

Rep: Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756
This should work for episodes 1 to 9 if run in a bash shell in the directory containing the files
Code:
for file in *; do echo "${file/Episode 0/1x}"; done
After checking, replace 'echo' with 'mv "$file"'.

It is left as an exercise to adjust this for more than 9 episodes.

Last edited by allend; 01-06-2013 at 07:58 AM.
 
1 members found this post helpful.
Old 01-09-2013, 06:20 AM   #3
Adol
Member
 
Registered: Feb 2011
Location: Osaka, Japan
Distribution: Gentoo, Opensuse
Posts: 271

Original Poster
Rep: Reputation: 6
Quote:
Originally Posted by allend View Post
This should work for episodes 1 to 9 if run in a bash shell in the directory containing the files
Code:
for file in *; do echo "${file/Episode 0/1x}"; done
After checking, replace 'echo' with 'mv "$file"'.

It is left as an exercise to adjust this for more than 9 episodes.
Thank you very much and sorry for the late reply.

Im going to try this out over the weekend.

Thank you.
 
Old 01-09-2013, 04:32 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Hello neighbor!

Try doing a forum search. There have been many, many, many previous threads about how to bulk rename files.
 
Old 01-12-2013, 06:10 AM   #5
Adol
Member
 
Registered: Feb 2011
Location: Osaka, Japan
Distribution: Gentoo, Opensuse
Posts: 271

Original Poster
Rep: Reputation: 6
Quote:
Originally Posted by David the H. View Post
Hello neighbor!

Try doing a forum search. There have been many, many, many previous threads about how to bulk rename files.
Sorry about that.

The problem with search is that many time I don’t know what to search for.

I`ll try to search more in the future.

Nice to see another forum member in Osaka.
 
Old 01-12-2013, 07:02 AM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
@Adol,
Can you share some sample entries of file that containing show/episodes list and sample output that you want?
Actually, I had tried it using a script, but without sample data it's not easy to suggest any solution.
 
Old 01-13-2013, 11:02 AM   #7
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
this has to be modified for each season:
Code:
i=01; while [ $i -le 13 ]; do ln -s frisky-dingo-$i-* frisky-dingo.1$i.mkv; i=`expr $i + 1 | awk '{printf "%.2d", $1}'`; done # season 1 scraping
x=01; while [ $i -le 25 ]; do ln -s frisky-dingo-$i-* frisky-dingo.2$x.mkv; x=`expr $x + 1 | awk '{printf "%.2d", $1}'`; i=`expr $i + 1`; done # season 2 scraping
this worx for me on xbmc. you can probably use the mv command instead of creating soft-links. you would need to use something like awk to parse the part of the filename (episode name) in the resultant filename.

Last edited by schneidz; 01-13-2013 at 11:24 AM.
 
  


Reply



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
to extract all the part of the filename before a particular word in the filename aealexanderraj Programming 1 08-27-2012 11:08 AM
[SOLVED] Shell script to find a filename in a folder & change text within the file Simon1984 Linux - Newbie 6 05-18-2012 07:09 AM
AWK/SED Inserting filename as part of the text dickGripper Linux - Server 3 01-03-2012 09:06 AM
Change name of backup file in ext3 from filename~ to .filename~ Libu Linux - General 2 07-21-2008 09:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:49 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
Open Source Consulting | Domain Registration