Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Per line ${..//..}

    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


    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