From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18833 invoked by alias); 21 Mar 2014 19:04:37 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 18652 Received: (qmail 19878 invoked from network); 21 Mar 2014 19:04:32 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=XyKeDmiv7JnWpDI8S8TU/3kXscefa768/DQjVEB5WRg=; b=wg61yJKLk+B/6HftWwIGllOHPTubAdMjy6qHLq+Gosry3sFlVtzMl3IWwHp//PDIjE wl0QONSZt6VdC/zx99e6Nc6cUk7oP7Wq5Rwrvye0Mvf859WZXO4IiqJ1AOWOrQzBM28T oQOMaOaY88O4iXAjJCF521PPaNY41jjJx98uW0irh+i8xy+HWYapNSmltbUQ1I6ywklk 1FpIfhCXC0nw8kmB6S4kgdw0ia8WQj3178I+hqIWsADMdtmgVyQ306uZ/iG4gfED+ZIs HsEiQJxF84Lf9rs1XMqWmh/3lg/tlPWCskeWy3w7BMiEebzkHk2+9j4K0Ci0DYeMHA0y HvrQ== X-Received: by 10.140.89.234 with SMTP id v97mr56576032qgd.20.1395428668390; Fri, 21 Mar 2014 12:04:28 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <140318144230.ZM15739@torch.brasslantern.com> References: <20140318202309.4d830a8b@pws-pc.ntlworld.com> <140318144230.ZM15739@torch.brasslantern.com> From: TJ Luoma Date: Fri, 21 Mar 2014 15:02:52 -0400 Message-ID: Subject: Re: Compare two (or more) filenames and return what is common between them To: Zsh-Users List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, Mar 18, 2014 at 5:42 PM, Bart Schaefer wrote: > On Mar 18, 8:23pm, Peter Stephenson wrote: > } Subject: Re: Compare two (or more) filenames and return what is common = bet > } > } On Tue, 18 Mar 2014 03:05:27 -0400 > } TJ Luoma wrote: > } > What I am trying to do: > } > > } > Given a folder/directory full of files (and, possibly, some existing > } > folders/directories), I want to create folders which will group files > } > with similar files names, but which will leave folders alone. > } > } I'm still not quite sure after reading your description what it is you > } want > > I suspect he wants something like this: > > http://en.wikipedia.org/wiki/Approximate_string_matching > > Zsh has such a function internally for "spelling" correction, but it is > actually based on correcting for typographical mistakes on a QWERTY > keyboard more than on traditional substring similarity. > > You could also try something with the (#a) glob qualifier (approximate > matching) but it's VERY expensive for strings as long as some of your > example file names and is entirely impossible to interrupt once it is > started ("kill -9" territory). I just realized that there=E2=80=99s a (seemingly) simpler example for what I=E2=80=99d like to be able to do in a shell-script instead of in an interactive shell. It wouldn=E2=80=99t have all of the features that I firs= t described, but I think it would be enough, and perhaps simpler to implement. When I have a bunch of files in a folder and need to match them, I start typing the letters and then press {tab} for completion, and it shows me the files that have similar =E2=80=9Croots=E2=80=9D For example, right now I just did: % ls 2[tab] and it expanded to % ls 2014-03-16. even though the matching files are named 2014-03-16.Sermon.aiff 2014-03-16.worship.aiff So here are the steps simpler version of what I=E2=80=99d like to do (which= , I realize, might not be possible to do in a shell script): 1. Find all of the files (not directories) in a given directory (that directory would probably be =E2=80=9C$@=E2=80=9C in most cases) 2. Type the first ~4 letters of each filename 3. Emulate {tab} for completion matching 4. Create a directory based on the output from step #3 5. Move whatever files matched step #3 into the folder created in step 4 Is that more clear and/or possible? Thanks! TjL