zsh-users
 help / color / mirror / code / Atom feed
From: DervishD <raul@pleyades.net>
To: Zsh Users <zsh-users@sunsite.dk>
Subject: Expanding when matching
Date: Fri, 23 Apr 2004 23:15:40 +0200	[thread overview]
Message-ID: <20040423211540.GA1821@DervishD> (raw)

    Hi all :)

    I have a couple of doubts about Parameter Expansion, namely in
the replacement field. The first doubt is just curiosity, of the kind
that kills cats... The end of string anchor doesn't seems to work:

    $ testvar="This is my test var"
    $ print ${testvar/This*/Replaced}
    Replaced
    $ print ${testvar/#This*/Replaced}
    Replaced
    $ print ${testvar/var/Replaced}
    This is my test Replaced
    $ print ${testvar/var%/Replaced}
    This is my test var
    $ print ${testvar/#This*%/Replaced}
    This is my test var

    The example doesn't make much sense, but it illustrates what I
mean. What I'm doing wrong? What am I not understanding?

    The second problem is more difficult, I'm afraid. This is best
explained with an example:

    counter=0 ; for number in {1..100}
    do
        print ${number/*0*/Hit a ten! $((counter++))}
    done

    What I want is the substitution (and the postincrement) expanded
and run only when the parameter matches, but instead it is
(correctly) expanded on each call. This is just an example, I'm not
trying to count 'tens', what I really need is a way of doing the
expansion of the replacement expression only when it is a match.

    How can I achieve this with zsh? BTW, what I'm trying to do is to
replace some numbers in one text that should be consecutive but are
not, and they are interspersed with arbitrary text. What I know about
them is that they are alone in a line, so they match certain regex,
no problem about that. But between two of those numbers may be two,
four, ten lines, I don't know :((

    I know, I can do it with awk or sed, but I want to do it with
zsh, just for the sake of it O:) Thanks a lot in advance and sorry
for the noise. Hope some day I'm able to return all the help I get
here :) Thanks, I mean it.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


             reply	other threads:[~2004-04-23 21:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-23 21:15 DervishD [this message]
2004-04-23 22:05 ` Wayne Davison
2004-04-24  7:48   ` DervishD
2004-04-24  4:14 ` Bart Schaefer
2004-04-24  7:57   ` DervishD

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=20040423211540.GA1821@DervishD \
    --to=raul@pleyades.net \
    --cc=zsh-users@sunsite.dk \
    /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).