delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2020/03/03/22:53:34

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:message-id:date:from:mime-version:to:subject
:references:in-reply-to:content-type:content-transfer-encoding;
q=dns; s=default; b=eNdC2/J2VsavYDbiat7HiRu+r6hJ9IdB2MyFI62gSd1
LaQT6+y3NXRKTUpLhN6ktgs0Ja77R8vYcEiL2q1c1GoUPLNfx36yN9Z8Ry37gR6U
NUcSBNvY/WegE+yBJIzMGhkh2FaHoj09Pkha9BaRQWeRzYVzDAT/xPgXT36BeARw
=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:message-id:date:from:mime-version:to:subject
:references:in-reply-to:content-type:content-transfer-encoding;
s=default; bh=3aHCHjQBwX2fA937HQqWTiSbuLo=; b=HEUn7fcMriArFlBEr
8F1r1FPkHKTP1tBqRuD3hC7h7bzSgiBSMRJl9IpBFFHOPmXkTiCj6HAp3Y1zPj4C
F9aGTwrDu4KZy9gAh0CNpPQ0I6MktcZz4N7nFHRZ0544nZmuQ7mlF0y/Jm5gQ9EW
8l8AE5CfrQG0N4gDJ3csFTEcEQ=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.1 spammy=
X-HELO: Ishtar.sc.tlinx.org
Message-ID: <5E5F2606.3070201@tlinx.org>
Date: Tue, 03 Mar 2020 19:52:38 -0800
From: L A Walsh <cygwin AT tlinx DOT org>
User-Agent: Thunderbird
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Has rename syntax changed?
References: <AM6PR03MB5282DB8DBC61B8331D880434A4E80 AT AM6PR03MB5282 DOT eurprd03 DOT prod DOT outlook DOT com> <5E5EE76B DOT 8000202 AT tlinx DOT org> <bc294a03-2796-a53e-c56f-a015a60f557c AT t-online DOT de>
In-Reply-To: <bc294a03-2796-a53e-c56f-a015a60f557c@t-online.de>
X-IsSubscribed: yes
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id 0243rFHG014874

On 2020/03/03 15:45, Hans-Bernhard Bröker wrote:
> Am 04.03.2020 um 00:25 schrieb L A Walsh:
>   
>> On 2020/02/28 04:38, Fergus Daly wrote:
>>     
>>> I am almost certain that the command
>>> $ rename "anything" "AnyThing" *.ext
>>> would alter the string from lc to uc as shown, anywhere it occurred in 
>>> any filename in *.ext in the current directory.
>>>       
>> isn't that they same as "mv anything.xxx Anything.xxx" ?
>>     
>
> No.  For three reasons:
>
> *) it's .ext, not .xxx :-)
> *) it will find and replace 'anything' _anywhere_in_ the filename, not 
> just in the basename.
>   
I'm confused about your terminology. If you type 'man basename', you'll
see something that is essentially this:

    basename = [optional directory name '/'] basename [. extension (or 
suffix)]

You said we are only working in 'cwd' so there is no directory name.

You said all of the filenames must match '*.ext'.  The only part
left after the extension, ".ext", is removed is the basename.  So while
your replacement can match _anywhere_in_ the filename, the filename and 
basename
are the same after it matched the listed 'extension', no?

Second, rename doesn't replace the string '_anywhere_' in the filename, 
but only
the first occurance:

>  rename anything AnyThing *.ext
>  ll *.ext
-rw-rw-rw-+ 1 0 Mar  3 19:24 oneAnyThingtwo.ext
-rw-rw-rw-+ 1 0 Mar  3 19:25 oneAnyThingtwoanythingthree.ext

While bash only works on 1 file at a time,
it can replace 1 or multiple occurances:

>  for f in *.ext;do
>  mv "$f" "${f//anything/AnyThing}"
>  done
>  ll *.ext
-rw-rw-rw-+ 1 0 Mar  3 19:24 oneAnyThingtwo.ext
-rw-rw-rw-+ 1 0 Mar  3 19:25 oneAnyThingtwoAnyThingthree.ext

If one wants to replace 1 occurance in multiple files, I would
still use 'mmv', as rename will overwrite files if there is a collision
whereas 'mmv' won't.







--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019