'tr' command driving me mad!
Greetings.
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:
Quote:
Quote:
This is what I have tried: Quote:
Thanks a bunch! |
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) 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. |
spiritreceiver,
I tried wht you suggested and I ended up with the following: Quote:
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:
Anyway, if someone who reads this thread knows what I'm trying to do, please post! Thanks! |
I didn't try this solution to prove it, but I'm about 99% sure that you just need to put you backticked echo command inside double quotes.
Like this: Code:
mv $i "`echo $i | tr blah blah blah`" |
Another way is to use rename. Your mp3 renaming could be done with
Code:
rename ".mp3" "" *.mp3 |
titopoquito,
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. Thanks anyway for your input. |
Quote:
|
Quote:
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. |
Quote:
|
$ echo "I'm-a-retard" | tr "-" " "
I'm a retard for i in *.txt;do mv "$i" `echo "$i" | tr "-" " "`; done |
All times are GMT -5. The time now is 10:19 AM. |