LinuxQuestions.org

LinuxQuestions.org (http://www.linuxquestions.org/questions/index.php)
-   Linux - Software (http://www.linuxquestions.org/questions/forumdisplay.php?f=2)
-   -   [Bash] Rename filenames with corresponding filenames (http://www.linuxquestions.org/questions/showthread.php?t=772635)

Power2All 12-01-2009 04:51 AM

[Bash] Rename filenames with corresponding filenames
 
Hi,

Im getting a headache of bash, and I got a question.

I got a filename called like this:
beach---------20090808-110000.ogg
beach---------20090808-120000.ogg

It's like this:
name----------YYYYMMDD-hhmmss.ogg

Now Im splitting these hourly files into 1 minute files.
I get then this output sofar properly:
beach---------20090808-110000_00.mp3
beach---------20090808-110000_01.mp3
beach---------20090808-110000_02.mp3

and so on....

the 00, 01, 02 and up are the minutes it has splitted it.
Now I need a script, after it did this, to rename the file names into this:

beach---------20090808-110000.mp3
beach---------20090808-110100.mp3
beach---------20090808-110200.mp3
beach---------20090808-110300.mp3

and so on...

Could anybody help me with perhaps fixing a script that this works ?
I could make something like this with PHP though, but I wish it to be a easy to work bash script, if possible.

centosboy 12-01-2009 05:53 AM

Quote:

Originally Posted by Power2All (Post 3775513)
Hi,

Im getting a headache of bash, and I got a question.

I got a filename called like this:
beach---------20090808-110000.ogg
beach---------20090808-120000.ogg

It's like this:
name----------YYYYMMDD-hhmmss.ogg

Now Im splitting these hourly files into 1 minute files.
I get then this output sofar properly:
beach---------20090808-110000_00.mp3
beach---------20090808-110000_01.mp3
beach---------20090808-110000_02.mp3

and so on....

the 00, 01, 02 and up are the minutes it has splitted it.
Now I need a script, after it did this, to rename the file names into this:

beach---------20090808-110000.mp3
beach---------20090808-110100.mp3
beach---------20090808-110200.mp3
beach---------20090808-110300.mp3

and so on...

Could anybody help me with perhaps fixing a script that this works ?
I could make something like this with PHP though, but I wish it to be a easy to work bash script, if possible.

perl batch rename is a perl module that can do this quite easily


http://search.cpan.org/~danboo/pbr-0.12/pbr

Power2All 12-01-2009 07:52 AM

Quote:

Originally Posted by centosboy (Post 3775569)
perl batch rename is a perl module that can do this quite easily


http://search.cpan.org/~danboo/pbr-0.12/pbr


Thanks, but I have no idea how to use expressions in regard to what I want.
Could someone point me out how to start ?

stevenworr 12-01-2009 02:20 PM

Code:

847 > cat ~/bin/rename
#!/usr/bin/perl
$op = shift;
for (@ARGV) {
    $was = $_;
    eval $op;
    die $@ if $@;
    rename($was,$_) unless $was eq $_;
}

Then you can do stuff like:

Code:

# Goal is to get from
# beach---------20090808-110000_99.mp3
# to
# beach---------20090808-119900.mp3
rename 's/^(beach---------\d{8}-\d\d)\d{4}_(\d\d).mp3)$/${1}${2}00.mp3/' *.mp3

Not tested. Give it a blast.

Power2All 12-02-2009 04:15 AM

Nice.
Thanks for the feedback.

I got this somehow working, but I got yesterday a PHP variant working already.
The thing about the PHP version is that I can hook it up on our administrator panel using a HTTP authentication as check and sessions.
Thanks for the information and I certainly keep this forum as one of my question basis for Linux :)


All times are GMT -5. The time now is 05:25 AM.