Re: remove double quote character from file names
Date: Thu, 16 Feb 2023 07:20:09 UTC
----------------------------------------
> From: Per olof Ljungmark <peo@nethead.se>
> Date: Feb 11, 2023, 6:58:50 AM
> To: <freebsd-questions@freebsd.org>
> Subject: remove double quote character from file names
>
>
> Hi all,
>
> A little help on the way, I need to find and remove the double quote (")
> character from all files in a directory structure containing hundreds of
> thousands of files.
>
> I am sure plenty of you have done this before... I've gotten as far as
>
> find . -type f -name '*"*' -exec rename 's|"|in|g' {} \;
> find: rename: No such file or directory
>
> The find part works but not renaming so I'm missing something there.
>
> Thanks,
> Per
>
>
Just to throw in an awk-themed solution:
$ ls -1 | awk '/"/ { system("mv -v '\''" $0 "'\'' " $0) }'
$ touch "\"foo bar\"" \"baz\" \".zap\" xyz abc
$ ls -1A
".zap"
"baz"
"foo bar"
abc
xyz
$ ls -1 | awk '/"/ { system("mv -v '\''" $0 "'\'' " $0) }'
".zap" -> .zap
"baz" -> baz
"foo bar" -> foo bar
$ ls -1A
.zap
abc
baz
foo bar
xyz
There's a clever use of the existing double-quotes in the filenames in the renaming.
--
Sent with https://mailfence.com
Secure and private email