LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-05-2009, 08:53 PM   #1
Dynadrate
LQ Newbie
 
Registered: Apr 2009
Posts: 1

Rep: Reputation: 0
Extract certain parts of a string


Hi there!
I'm new to linux, but quite motivated!
I have following Problem: There are video-files which I'd like to be sorted into directories.
At the moment, there is one huge directory:

TV.Show.foo.S01E02.Title.avi
TV.Show.foo.S02E08.Title.avi
TV.Show.bar.S03E14.Title.avi
TV.Show.bar.S07E01.Title.avi
...and so on.

I stumbled upon regular expressions, but i'm not sure wheter this technique can help me. For my understanding, the files have a pattern in the Season-Episode part of the filename (S**E**). So, everthing ahead of this should be returned and with this it would be easy to mkdir a directory and put the files in it. It would be even better if the dots would be removed, but that's not necessary.

It's not that i want anybody to do my research, i just want to know if i'm on the right way with regular expressions to achieve this. RegEx seem to be quite advanced, and i don't want to run into something which doesn't help me after all

I'm working on a NSLU2 with unslung, a special distro for this device. I have to add, that i can only use shell at the moment.

Thank you very much!
 
Old 04-05-2009, 10:35 PM   #2
shakezilla
Member
 
Registered: Jun 2005
Location: U.S.
Distribution: xubuntu 8.10, linux 2.6.27-11-generic
Posts: 78

Rep: Reputation: 16
Yes, regular expressions are probably the way you want to go. If you're looking to get the TV show name for each file, I think you could use something like this in perl:

Code:
my %destDir= ();

foreach my $filename (@allFilenames)
{
    $filename =~ m/^(.*)\.S\d\dE\d\d\..*\.avi$/;
    $destDir[$filename]= $1;
}
Please note, my perl is VERY rusty, so this may not be right. Also, this code assumes that every file name you'll be looking at follows the same pattern that you wrote in your post. Otherwise, things get more complicated. Other tools to work with regular expressions are sed and awk.

As always, test it before you actually move the files.
 
  


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
Extract value from string ewingtux Programming 1 12-27-2008 07:19 PM
Replacing certain parts of a string dipuasks Linux - Server 5 11-22-2008 07:09 AM
chopping away unwanted parts in string C's Brother Programming 3 11-02-2008 07:56 AM
Extract part of a string steven.c.banks Linux - General 7 05-07-2008 07:18 AM
complete string conversion - without parts evaluation slackie1000 Programming 9 01-06-2004 01:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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