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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
12-01-2009, 04:51 AM
|
#1
|
|
LQ Newbie
Registered: Dec 2009
Posts: 3
Rep:
|
[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.
|
|
|
|
12-01-2009, 05:53 AM
|
#2
|
|
Senior Member
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137
Rep: 
|
Quote:
Originally Posted by Power2All
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
|
|
|
|
12-01-2009, 07:52 AM
|
#3
|
|
LQ Newbie
Registered: Dec 2009
Posts: 3
Original Poster
Rep:
|
Quote:
Originally Posted by centosboy
|
Thanks, but I have no idea how to use expressions in regard to what I want.
Could someone point me out how to start ?
|
|
|
|
12-01-2009, 02:20 PM
|
#4
|
|
LQ Newbie
Registered: Oct 2008
Posts: 13
Rep:
|
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.
|
|
|
|
12-02-2009, 04:15 AM
|
#5
|
|
LQ Newbie
Registered: Dec 2009
Posts: 3
Original Poster
Rep:
|
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 
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 03:23 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|