Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a batch of files that have the following pattern:
[variable length name] # ABC.ABC
[variable length name] can be anything, that need to remain unchanged.
I need to mass rename all of these files to remove the " # ABC" portion.
I've been trying to work with perl expressions but guess I haven't gotten it right. Could use some help.
Here are some of the patterns I've tried:
# rename 's/ # ABC\.ABC$/\.ABC/ *.ABC'
# rename 's/. # ABC$/ /' *.ABC
... and a various other attempts.
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233
Rep:
not sure the exact syntax but you could try reading the file into an array, loping through the array and performing the rename operation on the array elements
PS - If you're using Bash4 (I don't know if 3.x can do it) you can do this without the sed, just by using shell variable substitution; I haven't played with that much yet (I'm stuck in my ways) so didn't suggest it; other members are more versed in the newer shell features and can give you better advice on that when they come around (or you can check out the bash man page).
The 'rename' command may come in handy here, I think, but I still don't get the exact nature of the problem. Maybe a few examples of input and output would help.
(I'm replying with my cell, so grammar may be problematic.)
I am using 'rename'. I cited examples in my first post, but here are more filename examples:
My file # 123.ABC
Your file # 123.ABC
Note the ' # 123' is what I need to remove. I need to keep the .ABC at the end.
At least you got what you needed accomplished by whichever means.
Honestly, I should look into simpler means of doing things sometimes -- but what the heck, the more ways we have to choose from, the better!
Best regards,
Sasha
P.S> there was another thread within the last few weeks, where someone was trying to use `rename` and it became apparent that `rename` may or may not exist on some machines, and may or may not be the SAME `rename` as it is on other machines. Just something to keep in mind, in case it one day doesn't work on some machine you happen to be using.
Last edited by GrapefruiTgirl; 03-16-2010 at 04:21 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.