From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26082 invoked from network); 17 Feb 2005 03:04:39 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 17 Feb 2005 03:04:39 -0000 Received: (qmail 37827 invoked from network); 17 Feb 2005 03:04:32 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 17 Feb 2005 03:04:32 -0000 Received: (qmail 18364 invoked by alias); 17 Feb 2005 03:04:15 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8513 Received: (qmail 18348 invoked from network); 17 Feb 2005 03:04:13 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 17 Feb 2005 03:04:13 -0000 Received: (qmail 36669 invoked from network); 17 Feb 2005 03:04:13 -0000 Received: from lyta.akte.de (217.160.134.217) by a.mx.sunsite.dk with SMTP; 17 Feb 2005 03:04:10 -0000 Received: (root@lyta.akte.de) by lyta.akte.de id ; Thu, 17 Feb 2005 04:04:05 +0100 KRecCount: 1 KInfo: virscan ok KInfo: !spam auth Received: from condor.int.spiegl.de (pD9E93FD2.dip.t-dialin.net [217.233.63.210]) by lyta.akte.de via kasmail (2.9) id ; Thu, 17 Feb 2005 03:03:58 GMT Received: from condor.int.spiegl.de (spiegl@localhost [127.0.0.1]) by condor.int.spiegl.de (8.13.2/8.13.2/Debian-1) with ESMTP id j1H33tEs004059 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Thu, 17 Feb 2005 04:03:55 +0100 Received: (from spiegl@localhost) by condor.int.spiegl.de (8.13.2/8.13.2/Submit) id j1H33t51004054 for zsh-users@sunsite.dk; Thu, 17 Feb 2005 04:03:55 +0100 X-Authentication-Warning: condor.int.spiegl.de: spiegl set sender to zsh.Andy@spiegl.de using -f Date: Thu, 17 Feb 2005 04:03:55 +0100 From: Andy Spiegl To: ZSH User List Subject: parameter expansion or regex question Message-ID: <20050217030355.GA2943@spiegl.de> Mail-Followup-To: ZSH User List Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-PGP-GPG-Keys: mail -s "send pgp" auto@spiegl.de X-Accepted-File-Formats: ASCII OpenOffice .rtf .pdf - *NO* Microsoft files please. X-why-you-shouldnt-use-MS-LookOut: http://www.jensbenecke.de/l-oe-en.php X-warum-man-MS-Outlook-vermeiden-sollte: http://www.jensbenecke.de/l-oe-de.php X-Message-Flag: LookOut! You are using an insecure mail reader which can be used to spread viruses. X-how-to-quote: http://www.afaik.de/usenet/faq/zitieren/ X-stupid-disclaimers: http://goldmark.org/jeff/stupid-disclaimers/ User-Agent: Mutt/1.5.5.1+cvs20040105i X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 In order to learn something new I decided to write a zsh script instead of a perl script and now I'm stuck. :-( The task is the following: I've got a filename consisting of any number of words separated by dots, e.g. file.one.as.an.example another.file.txt just.one.more.to.show.off This filename may (or may not) contain one of the strings q1 q2 q3 q4 q5 also separated by dots. More examples: file.one.q4.as.an.example q3.another.file.txt just.one.more.to.show.q1.off All I need now is the filename _without_ this "q<1-5>" string. The problem is that this string is normally surrounded by dots but not if it's at the beginning or end of the filename. One hour ago I thought that I finally solved it (see code snippet below) but then I found that it doesn't work if it e.g. contains the word "freq1." or ".q3po.". Oh, boy - it sounded so simple at first! Well, here is my current attempt: (input: FILENAME, output: CLEANFILENAME) post=${FILENAME#*q<1-5>.} if [ x"$post" = x"$FILENAME" ]; then # no string found -> nothing to do CLEANFILENAME=$FILENAME else pre=${FILENAME%q<1-5>.$post} # now pre is empty (q?.foobar.jpg) or terminates with a . (foo.q?.bar.jpg) if [ ! -n "$pre" ]; then CLEANFILENAME=$post elif [ ${pre%.} = $pre ]; then # no string found -> nothing to do CLEANFILENAME=$FILENAME else CLEANFILENAME=$pre$post fi fi In Perl I'd do it similar to this: FILENAME =~ /(^|.)q[1-5](.|$)/; But I have no idea how/whether zsh can handle regexps. Uffda, it's already way to late to think so I better go to bed now. Hope to hear from you guys tomorrow. Thanks, Andy. -- o _ _ _ ------- __o __o /\_ _ \\o (_)\__/o (_) -o) ----- _`\<,_ _`\<,_ _>(_) (_)/<_ \_| \ _|/' \/ /\\ ---- (_)/ (_) (_)/ (_) (_) (_) (_) (_)' _\o_ _\_v ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Whenever I watch TV and see those poor starving kids all over the world, I can't help but cry. I mean I'd love to be skinny like that, but not with all those flies and death and stuff. (Mariah Carey)