Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Feb 2023 11:24:31 +0100
From:      Polytropon <freebsd@edvax.de>
To:        Sysadmin Lists <sysadmin.lists@mailfence.com>
Cc:        freebsd-questions@FreeBSD.org, Per olof Ljungmark <peo@nethead.se>
Subject:   Re: remove double quote character from file names
Message-ID:  <20230216112431.8252a3d4.freebsd@edvax.de>
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
On Thu, 16 Feb 2023 08:20:09 +0100 (CET), Sysadmin Lists wrote:
> [...]
> 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.

This is actually a quite clever "ab"use of existing quotes.

Just a friendly sidenote:

Never expect anything. It _might_ be possible that filenames
such as

	foo "bar" blah.txt
	"meow" 123.dat
	doodle "boo" .c++
	-my brain hurts ."tar".gz

exist in the heap of files to be processed. Selecting a good
delimiter for input files is hard. Using the "IFS = \n" approach
works - as long as there are no newlines in filenames (which
I'm not sure could also be allowed)... ;-)



-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



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