From nobody Thu Feb 16 21:42:05 2023 X-Original-To: freebsd-questions@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PHpLq4B7Tz3rbSt for ; Thu, 16 Feb 2023 21:42:11 +0000 (UTC) (envelope-from sysadmin.lists@mailfence.com) Received: from wilbur.contactoffice.com (wilbur.contactoffice.com [212.3.242.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4PHpLq1QKXz458X for ; Thu, 16 Feb 2023 21:42:11 +0000 (UTC) (envelope-from sysadmin.lists@mailfence.com) Authentication-Results: mx1.freebsd.org; none Received: from fidget.co-bxl (fidget.co-bxl [10.2.0.33]) by wilbur.contactoffice.com (Postfix) with ESMTP id A7EEE99D; Thu, 16 Feb 2023 22:42:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1676583728; s=20210208-e7xh; d=mailfence.com; i=sysadmin.lists@mailfence.com; h=Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding; l=1915; bh=dCfkYnyLbEgghmCC2vv/E2FremewD5ENaZ229rnalKc=; b=Wv43MGefUcE9+o4A27mPeRI2g7WOw5evJFJl0Eq9UHJk11zgN57LsepDyESO+FWr f7D1C6unSapS789+BzhPkYvJmImZtKAZMGTdiqwdp60J9YRJaeArWOANA3Ipo32XHAj FD1MlpuFaasu8jCJnte77vv8LJFHZkzfMY0/S29+VujoU5pFn/XpvmYWYG/LGs0jSVP Un7LIenjtV11VGwapK62pZGqwfvR0FG4TM38iABFK/3gMuzhsf2jxYGnh5gzICTgiuz pRcWydzoZ5FI207eZa58irYiVmnwu1FT1zWHWMoIj9XPl/8m1NS+cVpS3Yol1cwXo0c YXu+YDXhjA== Date: Thu, 16 Feb 2023 22:42:05 +0100 (CET) From: Sysadmin Lists To: freebsd-questions@FreeBSD.org Cc: Per olof Ljungmark , Polytropon Message-ID: <380646460.28908.1676583725362@fidget.co-bxl> In-Reply-To: <20230216112431.8252a3d4.freebsd@edvax.de> References: <1398045780.627028.1676532009651@ichabod.co-bxl> <20230216112431.8252a3d4.freebsd@edvax.de> Subject: Re: remove double quote character from file names List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Mailer: ContactOffice Mail X-ContactOffice-Account: com:312482426 X-Rspamd-Queue-Id: 4PHpLq1QKXz458X X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:10753, ipnet:212.3.242.64/26, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N > ---------------------------------------- > From: Polytropon > Date: Feb 16, 2023, 2:24:31 AM > To: Sysadmin Lists > Cc: , Per olof Ljungmark > 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