[Bash] Rename filenames with corresponding filenames
Linux - SoftwareThis 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.
[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:
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.
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:
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
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
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.