Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Feb 2023 18:36:38 +0100
From:      Per olof Ljungmark <peo@nethead.se>
To:        questions@freebsd.org
Subject:   Re: remove double quote character from file names
Message-ID:  <e831a6ee-6763-33ee-722d-9a232ff213a4@nethead.se>
In-Reply-To: <119961fa-c43e-d78c-a0a1-0565535d0bb6@FreeBSD.org>
References:  <d83c93ad-0eac-d41a-c7db-79a1e1bc62d8@nethead.se> <105187d9-2510-9209-8b35-c273aa20076b@qeng-ho.org> <b20f01d5-1c8b-c0d6-cbc1-3bd2f1070335@nethead.se> <119961fa-c43e-d78c-a0a1-0565535d0bb6@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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!



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?e831a6ee-6763-33ee-722d-9a232ff213a4>