From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14358 invoked by alias); 18 Mar 2014 07:06:17 -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: 18618 Received: (qmail 19232 invoked from network); 18 Mar 2014 07:06:12 -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:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=RC2fWrON8xSig/sBB1H8RUG8XJ/l387GmUAERqyrj1Y=; b=bBDgYEw+XY9iLf3yhoEvxQJaRaROWjodLavuKZAWaL2TfLKkPsqbe/6mQM6WENnmcQ yTXiBnF0vqsh9JqQbbaAHYmr3x5syl1TPNIpKmLSlYUqjntEfeVfH6t9E4dvMaZxtnOf zAHJSHTw6eGlJuOfIigLnI5HLQqqv8Bq31CiUQNJbPW+yGiBRFgV/js0UrsNS3LEADvZ 5ZlDC6RY2NvZYQXCE1dFQ1Sq5IK89cn9/HwE11LF/D38umirKOK5CaLYb1GWSC3VSzoG 3b+pqRmWgZNBASTR3J5utCP860a7sb10nW5cZdoega2kTGufwShedRXzjLi+/bAc6yby jR1Q== X-Received: by 10.224.112.6 with SMTP id u6mr8877141qap.78.1395126368636; Tue, 18 Mar 2014 00:06:08 -0700 (PDT) MIME-Version: 1.0 From: TJ Luoma Date: Tue, 18 Mar 2014 03:05:27 -0400 Message-ID: Subject: 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 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. For example, here=E2=80=99s a list of files from a directory: @TUAW Adding Low Power Bluetooth to your older Mac.md all-tuaw-posts-with-titles.txt Fluid_1.8.zip FSB- Yellow King.md fsb-followup.md iCXItGrjqrw --- ATP_Ending_Theme_Song_A_Day_1546 18_-_640x360 18.mp4 iCXItGrjqrw --- ATP_Ending_Theme_Song_A_Day_1546 18_-_640x360 18.mp4.description.txt Narrative Lectionary 2013-2014 Readings for Year 4 (Gospel of John).pdf Narrative Lectionary Summer 2014.pdf qq Set a Mac's Hostname in Terminal.txt rss-audio-template-index.xml rsync-skip-compress.txt Tumblr Private Posts.txt afterwards, I would like all of the above files to have been sorted into these folders: @TUAW Adding Low Power Bluetooth to your older Mac all-tuaw-posts-with-titles Fluid_1.8 FSB- Yellow King fsb-followup iCXItGrjqrw --- ATP_Ending_Theme_Song_A_Day_1546 18_-_640x360 18 Narrative Lectionary qq Set a Mac's Hostname in Terminal rss-audio-template-index rsync-skip-compress Tumblr Private Posts The only really tricky part here is for a few of the files which share part or all of their filename: iCXItGrjqrw --- ATP_Ending_Theme_Song_A_Day_1546 18_-_640x360 18.mp4 iCXItGrjqrw --- ATP_Ending_Theme_Song_A_Day_1546 18_-_640x360 18.mp4.description.txt (which should both go into a folder "iCXItGrjqrw --- ATP_Ending_Theme_Song_A_Day_1546 18_-_640x360 18=E2=80=9D) (Let=E2=80=99s called this =E2=80=9CCase #1=E2=80=9D) and Narrative Lectionary 2013-2014 Readings for Year 4 (Gospel of John).pdf Narrative Lectionary Summer 2014.pdf (which should both go into a folder "Narrative Lectionary=E2=80=9D) (Let=E2=80=99s called this =E2=80=9CCase #2=E2=80=9D) Also notice that "rss-audio-template-index.xml=E2=80=9D and "rsync-skip-compress.txt=E2=80=9D should _not_ go into a folder called =E2= =80=9Crs=E2=80=9D (Let=E2=80=99s called this =E2=80=9CCase #3=E2=80=9D) Case #1 seems like it should be pretty easy, because all I would have to do is take off the extension(s) and both of the files have the same =E2=80=9Croot=E2=80=9D so I guess I could match that somehow, but I=E2=80= =99m not exactly sure how since one file has ".mp4.description.txt=E2=80=9D and one file has =E2= =80=9C.mp4=E2=80=9D Case #2 - I am not sure how to efficiently match those two=E2=80=A6 I guess= I could start comparing letters of each filename and then stop when they don=E2=80=99t match, but I=E2=80=99m not even sure how to do that. (And I j= ust realized that I would not want a trailing space in the folder name either so it would have to be smart enough to deal with that somehow too so I end up with a folder named "Narrative Lectionary=E2=80=9D not "Narrative Lectionary =E2=80=9D!) For "Case #3=E2=80=9D I guess I need to set some sort of minimum number of characters to be matched. Maybe=E2=80=A6 5? I don=E2=80=99t really know how= to deal with that case very well. Has anyone already invented this? If not, can anyone suggest how I might go about doing this? I=E2=80=99ve be= en trying to come up with something and I=E2=80=99m just at a complete loss to know where to start, and I get the strong suspicion that there might be a zsh feature that would help that I just don=E2=80=99t know about. Thanks for any help you can offer. TjL