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 12-01-2009, 04:51 AM   #1
Power2All
LQ Newbie
 
Registered: Dec 2009
Posts: 3

Rep: Reputation: 0
[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.
 
Old 12-01-2009, 05:53 AM   #2
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by Power2All View Post
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
 
Old 12-01-2009, 07:52 AM   #3
Power2All
LQ Newbie
 
Registered: Dec 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by centosboy View Post
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 ?
 
Old 12-01-2009, 02:20 PM   #4
stevenworr
LQ Newbie
 
Registered: Oct 2008
Posts: 13

Rep: Reputation: 1
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.
 
Old 12-02-2009, 04:15 AM   #5
Power2All
LQ Newbie
 
Registered: Dec 2009
Posts: 3

Original Poster
Rep: Reputation: 0
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
 
  


Reply

Tags
file, name, rename


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
Insert additional characters into filenames to rename them. Trap Linux - General 4 05-14-2009 06:25 AM
bash, filenames, special chars zomane Programming 3 06-15-2007 04:55 AM
bash and filenames with special characters CoolAJ86 Programming 2 03-09-2005 02:50 PM
Spaces in filenames with BASH edenning Programming 12 01-27-2005 07:10 AM
bash and filenames with spaces doctorwebbox Linux - General 2 12-15-2004 08:55 PM


All times are GMT -5. The time now is 12:43 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration