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.
I have been reading the man and info pages and various online guides concerning the 'tr' command and I am getting absolutely nowhere. I've created a file with 'vim' and I want to alter the filename with 'tr' and
I'm stuck. Here is the filename:
Quote:
text-to-test-on.txt
What I am trying to accomplish is this:
Quote:
text to test on.txt
I am looking to replace the '-' with a whitespace. I know I can accomplish this with the rename command via
I guess the problem is the for loop. I loops over the content of *.txt separated by space characters, i.e. "text to test on.txt" will lead to four cycles. Try the following:
Code:
(IFS=$'\n'; for i in *.txt;do mv "$i" `echo $i | tr [:space:] '-' `; done)
Search "man bash" for IFS to see what's going on.
Edit: Seems like I was wrong. You could try using echo -n "$i" instead of echo $i, but I don't think it will make much of a difference. Try and use the "set -x" command to find out what's going on in detail.
Last edited by spirit receiver; 10-06-2006 at 09:22 AM.
I tried wht you suggested and I ended up with the following:
Quote:
text-to-test-on.txt
IFS=$'\n';for i in *.txt;do mv "$i" `echo $i | tr [:space:] '-'`;done
text-to-test-on.txt-
It added a '-' to the end. I'm actually laughing at this. (I guess I'm starting to mature. I used to get angry when something didn't work.)
The reason I'm trying so hard to learn this is because I was experimenting with a whole directory of mp3 files and I wanted to remove the '.mp3' from each file. What I ended up with was this:
Quote:
Name-of-song.mp3.mp3.mp3.mp3
Thats not what I was looking for!
Anyway, if someone who reads this thread knows what I'm trying to do, please post!
In my original post I mentioned that I know I can use the 'rename' command.
I have a directory of mp3's that I accidentally renamed to 'song.mp3.mp3.mp3.mp3'.
'tr' is the command that I am trying to learn.
It bothers me when people don't read the complete thread and jump in and offer a suggestion without regard to the whole thread.
Distribution: Slackware64 14.2 and current, SlackwareARM current
Posts: 1,644
Rep:
Quote:
Originally Posted by Freestone
titopoquito,
In my original post I mentioned that I know I can use the 'rename' command.
It bothers me when people don't read the complete thread and jump in and offer a suggestion without regard to the whole thread.
Thanks anyway for your input.
I actually read your post, but you first said you wanted to substitute dashes with spaces and rename is probably not the best command to do this (since it replaces only the first occurance of the replace pattern). You wrote later about changing the file extensions for which rename IS a good solution. So no offense intended, but it was not clear to me that you didn't want to use "rename" for BOTH.
It bothers me when people don't read the complete thread and jump in and offer a suggestion without regard to the whole thread.
I have a suggestion here. It's usually counterproductive to throw out veiled holier-than-thou digs at those trying to help you.
FWIW, there are lots of threads on these forums. Lots! I read and respond to quite a few, as do many other people offering their help for free. I can only speak for myself, but I do not read every post in every thread. I typically look at the original post, quickly scan it (not necessarily read it in depth), to see what the jist of the problem is. Then I quickly scan responses to see if my initial thoughts have already been covered by any other responder, or whether another responder has offered advice that I consider bad or incorrect.
This is because posts are often times overly verbose. My own are a prime example of this. What can be said in ten words, I'll say in 17,386. I know and understand this about myself, and certainly wouldn't fault someone for skimming my words and picking out the ten that are actually relavent.
The jist I picked up from your post was "Here's a guy who has filenames with dashes in them and he wants to rename those with spaces." I did scan a tad further, and picked up on your comment about "learning tr", so I dropped you a hint that related to spaces in filenames and double quotes. Didn't spell it out for you, but dropped you a hint.
You have to realize that your typical post-responder-helper-person may very well scan right over your "supporting details", home in on the "synopsis", and write off what you've already tried (and failed at) as "He's trying something pretty weird and inefficient, I'll suggest a better way."
I don't know about titopoquito, but I hit "submit reply" on my post above as I was being harried by my daughter, "Come on Dad, we have to go!" I did not preview it, nor reread your original post (things I usually do). Just a quick "I'll throw this guy something, and maybe it might help him". My suggestion may have been well off-base since it was done in haste without a complete question and thread review.
If it bothers you that people try to quickly help you without analyzing every word you have typed previously, it bothers me that you actually expect people to help you in the first place.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.