From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17316 invoked by alias); 11 Oct 2015 20:09:10 -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: 20737 Received: (qmail 28488 invoked from network); 11 Oct 2015 20:09:08 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Originating-IP: [80.3.228.158] X-Spam: 0 X-Authority: v=2.1 cv=RLtOZNW+ c=1 sm=1 tr=0 a=P+FLVI8RzFchTbbqTxIDRw==:117 a=P+FLVI8RzFchTbbqTxIDRw==:17 a=NLZqzBF-AAAA:8 a=kj9zAlcOel0A:10 a=QLLfA3QzN6YtRUxCfPEA:9 a=CjuIK1q_8ugA:10 Date: Sun, 11 Oct 2015 21:09:02 +0100 From: Peter Stephenson To: Zsh Users Subject: Re: subsitutions and beginning of lines. Message-ID: <20151011210902.566de251@ntlworld.com> In-Reply-To: <561AB49A.4060801@eastlink.ca> References: <561AB49A.4060801@eastlink.ca> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.28; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 11 Oct 2015 12:12:26 -0700 Ray Andrews wrote: > ${var// /} > > When doing that sort of substitution, is is possible to test for newlines? > I'm playing with a function that grabs history and I'm trying to strip > off the leading numbers. At one point I have the output captured in a > variable and various forms of substitution come close, but the substitution > treats the entire variable as one entity whereas I want the substitution > to be performed fresh on each new line of output. I can't find any > specific newline character. OTOH if the variable was an array there'd > probably be some way of processing each line as a separate entity, which > would serve fine. I know I'm close, but I can't quite bag it. If I'm following, you are indeed nearly there: you need to split the variable to an array on newlines, while not splitting on anything else. To do that, you quote the array, then force the splitting which ensures it only gets split on what you tell it and not other other random spaces: var="1:one two 2:three four" print -l -- ${(f)"${var}"} The -l prints one element per line for clarity. You've now got the lines you want as if they were array elements. You can then surround that substitution with the sort you first thought of. For example, to strip the "number:", print -l -- ${${(f)"${var}"}##<->:} where, as you now know, <-> matches any set of digits. pws