[NTLUG:Discuss] remove apostrophe from filenames
David Stanaway
david at stanaway.net
Sun Jul 29 23:33:05 CDT 2007
What if the filename starts with a - or has a new line, what if the
renamed file already exists?
I would do this with perl to avoid headaches being sure you have escaped
the file names the right way.
If you are doing this to make some script work, you would be better
served making the script work no mater how the file is named.
Here is a kind of ugly way to do it in perl with use of find/xargs - it
will clobber already existing files.
find . -name "*'*" -print0 | xargs -0 perl -e "foreach(@ARGV){
\$s=\$d=\$_;\$d=~s/'//g; rename \$s, \$d};"
Robert Citek wrote:
> On 07/29/2007 09:47 PM, Robert Citek wrote:
>> On 07/29/2007 04:56 PM, Mike LaPlante wrote:
>>> Can someone give me a quick script check for and remove apostrophes from
>>> a ton of filenames. Doesn't have to be recursive, but won't hurt if it is.
>>>
>>> I've been trying a very some simple "for" loops involving tr -d "'" but
>>> I'm having trouble.
>> Assuming you're using bash, here's a sample:
>>
>> $ touch a "a'b" "a b"
>> ...
>> $ find . -name "*'*" | while read name ; do
>> mv "$name" "${name/\'/}"; done
>
> Or more complete:
>
> touch a "a'b" "a b" "a'b'c"
> ls -1
> find . -name "*'*" | while read name ; do
> mv "$name" "${name//\'/}"
> done
> ls -1
>
> Regards,
> - Robert
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
>
More information about the Discuss
mailing list