file renaming question--replace multiple instances
I've been trying to use the rename command to remove certain non-standard characters from filenames, but I can't get it to work the way I want.
Now the rename command uses pretty much the same syntax as sed. Trouble is, I don't know sed well enough to make this work. I can usually use the 'y/a/b/' substitution syntax to replace all instances of a character with another. But let's say, for example, that I want to simply remove all instances of commas from a filename, say "Beatles--long,_long,_long.ogg". If I try something like: rename 'y/,//' it completely fails to work. It appears to be because the substitution field is blank; it needs something to replace the comma with. But I don't want it to be replaced with anything, or rather, I want it to be replaced with nothing. I just want the character removed from the file name. I can run rename 's/,//' with no problem, but that only replaces the first instance of the quote in the name, so I have to run it multiple times to be sure I got everything. Even worse is something like rename 'y/[,\']//' where I want to remove both commas and apostrophe marks (Beatles--Honey,_Don't.ogg). So my question is, what syntax do I have to use to remove multiple instances of a character? My eventual goal is to to create a simple 'removefilenamejunk' alias or command that I can run whenever I want to clean up a file name. Thanx. |
Quote:
|
Quote:
Code:
echo $string | sed 's/,//g' |
I just knew it would be something simple like that. I swear though that I'd tried the g flag sometime in my searching and had no luck. Must've done something wrong. Besides, the sed man page only gives g as:
g G Copy/append hold space to pattern space. which doesn't sound anything like "global" replacement to me. I'm not even sure what "hold space" and "pattern space" mean, exactly. Anyway, I learned something new. Thanks! |
Quote:
|
All times are GMT -5. The time now is 01:31 AM. |