Re: remove double quote character from file names
- In reply to: Polytropon : "Re: remove double quote character from file names"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 16 Feb 2023 21:42:05 UTC
> ---------------------------------------- > From: Polytropon <freebsd@edvax.de> > Date: Feb 16, 2023, 2:24:31 AM > 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 > > > 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, ... > Those are good points. But in this case we know what happened: The OP accidently named a bunch of files with double-quotes when he meant to simply enclose them in double-quotes. Which means those possible edge cases aren't present. Still good points worth considering for other scenarios. -- Sent with https://mailfence.com Secure and private email