Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Feb 2023 09:35:35 +0100 (CET)
From:      Sysadmin Lists <sysadmin.lists@mailfence.com>
To:        freebsd-questions@freebsd.org
Cc:        Per olof Ljungmark <peo@nethead.se>
Subject:   Re: remove double quote character from file names
Message-ID:  <1476195320.633098.1676536535118@ichabod.co-bxl>
In-Reply-To: <1398045780.627028.1676532009651@ichabod.co-bxl>
References:  <d83c93ad-0eac-d41a-c7db-79a1e1bc62d8@nethead.se> <1398045780.627028.1676532009651@ichabod.co-bxl>

next in thread | previous in thread | raw e-mail | index | archive | help
> ----------------------------------------
> From: Sysadmin Lists <sysadmin.lists@mailfence.com>
> Date: Feb 15, 2023, 11:20:09 PM
> To: <freebsd-questions@freebsd.org>
> Cc: Per olof Ljungmark <peo@nethead.se>
> Subject: Re: remove double quote character from file names
> 
> 
>  ----------------------------------------
> > 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.
Here's what the shell sees:
$ ls -1 | awk '/"/ { print("mv -v '\''" $0 "'\'' " $0) }'
mv -v '".zap"' ".zap"
mv -v '"baz"' "baz"
mv -v '"foo bar"' "foo bar"

"Directory structure." In that case,
find . -type f -execdir awk -v file='{}' 'BEGIN { if (file ~ /"/) system("mv -v '\''" file "'\'' " file) }' \;
or
find . -type f -name \"\*\" -execdir awk -v file='{}' 'BEGIN { system("mv -v '\''" file "'\'' " file) }' \;

Again, replacing system() with print() shows what the shell sees.


-- 
Sent with https://mailfence.com  
Secure and private email



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1476195320.633098.1676536535118>