Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Compare two (or more) filenames and return what is common between them
- X-seq: zsh-users 18652
- From: TJ Luoma <luomat@xxxxxxxxx>
- To: Zsh-Users List <zsh-users@xxxxxxx>
- Subject: Re: Compare two (or more) filenames and return what is common between them
- Date: Fri, 21 Mar 2014 15:02:52 -0400
- 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==
- In-reply-to: <140318144230.ZM15739@torch.brasslantern.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CADjGqHt4xeQ=CGDSHOm8FCtK+PgndvEXnLA_WWU-OSd7D0xK-w@mail.gmail.com> <20140318202309.4d830a8b@pws-pc.ntlworld.com> <140318144230.ZM15739@torch.brasslantern.com>
On Tue, Mar 18, 2014 at 5:42 PM, Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> 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 <luomat@xxxxxxxxx> 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’s a (seemingly) simpler example for what
I’d like to be able to do in a shell-script instead of in an
interactive shell. It wouldn’t have all of the features that I first
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 “roots”
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’d 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 “$@“ 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author