zsh-users
 help / color / mirror / code / Atom feed
From: TJ Luoma <luomat@gmail.com>
To: Zsh-Users List <zsh-users@zsh.org>
Subject: Re: Compare two (or more) filenames and return what is common between them
Date: Fri, 21 Mar 2014 15:02:52 -0400	[thread overview]
Message-ID: <CADjGqHstjyABkL6BqetJ7wHqGhE-3wc-toU8FsifkP3kMGqLmA@mail.gmail.com> (raw)
In-Reply-To: <140318144230.ZM15739@torch.brasslantern.com>

On Tue, Mar 18, 2014 at 5:42 PM, Bart Schaefer
<schaefer@brasslantern.com> 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@gmail.com> 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


  reply	other threads:[~2014-03-21 19:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-18  7:05 TJ Luoma
2014-03-18 20:23 ` Peter Stephenson
2014-03-18 21:42   ` Bart Schaefer
2014-03-21 19:02     ` TJ Luoma [this message]
2014-03-21 19:39       ` Peter Stephenson
2014-03-28 20:20   ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADjGqHstjyABkL6BqetJ7wHqGhE-3wc-toU8FsifkP3kMGqLmA@mail.gmail.com \
    --to=luomat@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).