LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-27-2008, 10:02 AM   #1
Scorpuk
LQ Newbie
 
Registered: Jul 2008
Posts: 3

Rep: Reputation: 0
Need help creating a script to delete part of a filename


Currently running Ubuntu 8.04 with MythTV 0.21.

I have run mythrename.pl to rename my recordings by "Title - Subtitle - Year-Month-Day.mpg"

So I end up like this:

"Heroes - Four Months Ago - 2008-06-05.mpg"

Unfortunately some of the subtitles are listed as "Untitled". This is the part I would like to remove.

ie change

"Black Hawk Down - Untitled - 2008-07-02.mpg"

into

"Black Hawk Down - 2008-07-02.mpg"



Is this possible?


Thanks for any assistance in this. :-)
 
Old 07-27-2008, 10:32 AM   #2
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,089

Rep: Reputation: 196Reputation: 196
Probably a better way, but -

Code:
for i in *.mpg;do if [[ "$i" =~ " Untitled " ]];then mv "$i" "`echo $i | sed 's/- Untitled//'`";fi;done
 
Old 07-28-2008, 10:19 AM   #3
Scorpuk
LQ Newbie
 
Registered: Jul 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks arizonagroovejet for that, but it didnt work:


put the command(s) in a .sh file (added #!/bin/sh to start of it), made it executable and then ran it.

The output I got from it was:


Quote:
./untitled.sh: 3 : [[: not found
repeated the same amount of times as I had files.

I then tried removing the [[ and ]]'s. This looked more promising, but still no cigar.


The output I got was like this:

Quote:
./untitled.sh: 3: Toy Story 2 - Untitled - 2008-03-22.mpg: not found

repeated for each file with or without "- Untitled".


But no name change.


my file:

Code:
#!/bin/sh

for i in *.mpg;do if "$i" =~ " Untitled";then mv "$i" "`echo $i | sed 's/- Untitled//'`";fi;done

Edit:

Silly me... Ran the original command from the CLI and worked. No output on screen, but names have been changed

Last edited by Scorpuk; 07-28-2008 at 10:24 AM. Reason: Eurika !!!!
 
  


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
Shell script to read part of filename fatgoth Linux - Newbie 10 02-26-2012 08:21 AM
Storing part of a filename as a variable VTGuitarMan Programming 5 03-12-2008 06:47 AM
how to use environment variable as part of filename beeblequix Linux - Newbie 3 07-11-2006 04:55 PM
Getting the first part of a filename in a BASH script trevelluk Programming 3 02-15-2005 01:06 AM
put date as part of filename box_l Programming 3 07-27-2004 06:17 AM


All times are GMT -5. The time now is 07:09 PM.

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