From nobody Sat Feb 11 17:36:38 2023 X-Original-To: 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 4PDd7v5pvZz3pjC2 for ; Sat, 11 Feb 2023 17:36:43 +0000 (UTC) (envelope-from peo@nethead.se) Received: from ns1.nethead.se (ns1.nethead.se [5.150.237.139]) (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-signature ECDSA (P-384) client-digest SHA384) (Client CN "ns1.nethead.se", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PDd7t6FFTz4Q7f for ; Sat, 11 Feb 2023 17:36:42 +0000 (UTC) (envelope-from peo@nethead.se) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=nethead.se header.s=NETHEADSE header.b=WJRoldbf; spf=pass (mx1.freebsd.org: domain of peo@nethead.se designates 5.150.237.139 as permitted sender) smtp.mailfrom=peo@nethead.se; dmarc=pass (policy=none) header.from=nethead.se X-Virus-Scanned: amavisd-new at Nethead AB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nethead.se; s=NETHEADSE; t=1676136999; bh=m/x/q7KIEtFi0CbRaTgV1CVRUOMvoAtRIAgp52UhLfU=; h=Date:Subject:To:References:From:In-Reply-To; b=WJRoldbfew9YHNztCf5Igvi0Qm9jhf+4ClVNBFFtgibvAwzdx67mCwXL9siOJBzwc mVwOYMQUvqTxhnWdcQAz7nBeHXdo4KeHxzPpDCLsteU2r5l+GRxrxFi+a8YQ0iifuW dr/UseiHp3pEr1OpzccrbNFWRr3Lsn9+BrWZIhEA= Message-ID: Date: Sat, 11 Feb 2023 18:36:38 +0100 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 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: remove double quote character from file names Content-Language: en-US To: questions@freebsd.org References: <105187d9-2510-9209-8b35-c273aa20076b@qeng-ho.org> <119961fa-c43e-d78c-a0a1-0565535d0bb6@FreeBSD.org> From: Per olof Ljungmark In-Reply-To: <119961fa-c43e-d78c-a0a1-0565535d0bb6@FreeBSD.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-4.00 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-0.999]; DMARC_POLICY_ALLOW(-0.50)[nethead.se,none]; R_SPF_ALLOW(-0.20)[+ip4:5.150.237.139:c]; R_DKIM_ALLOW(-0.20)[nethead.se:s=NETHEADSE]; MIME_GOOD(-0.10)[text/plain]; MLMMJ_DEST(0.00)[questions@freebsd.org]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_ZERO(0.00)[0]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ASN(0.00)[asn:8473, ipnet:5.150.192.0/18, country:SE]; FROM_HAS_DN(0.00)[]; DKIM_TRACE(0.00)[nethead.se:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-Rspamd-Queue-Id: 4PDd7t6FFTz4Q7f X-Spamd-Bar: --- X-ThisMailContainsUnwantedMimeParts: N On 2/11/23 18:28, Matthew Seaman wrote: > On 11/02/2023 16:13, Per olof Ljungmark wrote: >> On 2/11/23 16:45, Arthur Chance wrote: >>> On 11/02/2023 14:58, Per olof Ljungmark wrote: >>>> 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. >>> >>> There's no rename command in the base system. Perhaps you meant to >>> install the sysutils/rename pkg but forgot? >>> >> >> No, I thought rename was part of the base system stupid me. So, >> without installing more ports I suppose sed(1) could do the job? >> > > The tools from the base system that you need here are find(1), sed(1), > mv(1) and sh(1).  Something like the following _completely_ _untested_ > code: > > ``` > #!/bin/sh > > for oldfname in $( find . -type f -name '*"*' -print ); do >     newfname=$( echo $oldfname | sed -e 's/"/in/g' ) >     echo mv -nv $oldfname $newfname > done > ``` > > This prints out a list of 'mv' commands to effect the change you want. > Which, as someone else wisely said you should examine closely to ensure > it is actually doing the right thing. Then, when you're satisfied that > it is, change 4 to read: > >    mv -nv $oldfname $newfname > > ensure you have good backups, and go for it. > Exactly what I needed, thanks a lot!