Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Per line ${..//..}
- X-seq: zsh-users 9564
- From: DervishD <zsh@xxxxxxxxxxxx>
- To: Peter Stephenson <pws@xxxxxxx>
- Subject: Re: Per line ${..//..}
- Date: Wed, 26 Oct 2005 12:15:29 +0200
- Cc: Zsh Users <zsh-users@xxxxxxxxxx>
- In-reply-to: <EXCHANGE03kJJfYCank000081b9@xxxxxxxxxxxxxxxxxx>
- Mail-followup-to: Peter Stephenson <pws@xxxxxxx>, Zsh Users <zsh-users@xxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: DervishD
- References: <20051026094047.GA658@DervishD> <EXCHANGE03kJJfYCank000081b9@xxxxxxxxxxxxxxxxxx>
Hi Peter :)
* Peter Stephenson <pws@xxxxxxx> dixit:
> DervishD wrote:
> > I have a parameter containing a bunch of lines, and I have to get
> > rid of comments (that is "$line" == (#s)[" $'\t'"]#\#*(#e)) and empty
> > lines (that is "$line" == (#s)[" $'\t'"]#(#e)). I've tried using the
> > ${..//..} syntax for doing substitutions in parameters, but with no
> > success because I don't know how to properly mark the beginning and
> > end of a line.
>
> You can do something like:
>
> % lines=(foo "# comment" bar " ")
> % print -l $lines
> foo
> # comment
> bar
>
> % print -l ${lines:#[[:space:]]#(\#*|)}
> foo
> bar
Unfortunately the original data is not in an array :( Will this
work?:
olddata=(${(f)olddata))
olddata=(${olddata:#...})
I completely forgot about the ${NAME:#PATTERN}. Better said, I
was stuck with ${..//..}. Thanks a lot for the suggestion. You've
given me another idea... I can convert all parameters that store file
contents into arrays, although some of them have \C-M as newline
markers, but that's easy to solve. This way I can do per-line
processing without the need for loops.
Raúl Núñez de Arenas Coronado
--
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...
Messages sorted by:
Reverse Date,
Date,
Thread,
Author