Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's 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.
Distribution: Ubunto and slowly switching to debian
Posts: 308
Rep:
replacing part of filename
I have just re transcoded a bunch of avi's. to tell the new ones from the old ones I put '[xvid]' at the end of all the new avi's. but now I have deleated the old avi's I want to remove the [xvid] part of the file name.
This is what I have so far
Code:
#!/bin/bash
for name in *.avi
do
newname=`echo "$name" | tr -d [xvid]`
echo "$name" "$newname"
mv "$name" "$newname"
done
##########
but that just removes all the leters X, V, I & D from the file name and doesnt actualy remove the string '[xvid]' from the file name.
any point in the wright direction would be helpfull
Generally if you give a script that is not working it always helps to provide what your starting with and
how you want it to look. Are we to assume that the file names may contains spaces as in your example:
Quote:
"video [xvid].avi"
Because your output does not only remove the desired string of "[xvid]" but also the prior space.
Assuming we can ignore the space, the following, which builds on catkin's approach, should work:
Code:
#!/bin/bash
for name in *.avi
do
newname=${name/\[xvid\]/}
echo mv "$name" "$newname"
done
Hmm, that looks more like a sed/regex. Looks like you have a different version of 'rename' to me.
The slackware one uses this syntax http://linux.die.net/man/1/rename
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.