From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15098 invoked by alias); 26 Nov 2015 20:17:32 -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: 20999 Received: (qmail 23994 invoked from network); 26 Nov 2015 20:17:30 -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,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version:content-type; bh=vrAmOD6pka4mrexbB5cn4SYfn8VXYQ58leZ1+Y/wj+k=; b=xamCPJEUl6uS9HCtMuMMoaFiybwVIakinlp6psd1QOltqERzd7SvxccSOQd7sVJtkC giPQ6ix/2PCBgnpw/5ZYmVqr920HM5d8shS31izV3PhYGrJvIVXQ7xgCPXbg5Fj4/vaG 1WXS+LHs1/WJm0gxJ8z10+d8smf6WLOXym4hebOx4Elj6Of7SZkgcPgDAdmFvGo4LP5o S9y2Y4UX6rmePB6TEWQLZJdXDeei4srglHDFS0e0L/Kri4snYrbvQ6Mmi6/NJygzEJeo R+PV3BSM1Q3Z9wTlbuD4tc79UnAot5iCp3AG8XPm1K9eHJ0d1JllbLx/mbJrjRPfjgxi EyDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=vrAmOD6pka4mrexbB5cn4SYfn8VXYQ58leZ1+Y/wj+k=; b=VkGZCx68k7cKL0indlvcLycU1j/PmLVcswGh4Bto93fucxA/UtukCjAlcaAJOJezRi AVGJIBneh2sNrtueuTmP+Fx3Q0e3ZDok2rSEge3GPEgwCajciTa9DCMcyNSZNTsKm91f utTim2PfuexP+macWHAbOQvQo5Ir1sBt8eMWQD4oiBpF9WEf5ceLloD5+kDWHNlXIwOJ twUpQh2I9WZWEUFWEM8fmnUtcwKu8OFUStLH4pyQfCLmFArVRk292XDMsQXAC4vd15Lf 4XR2apaPDRdIDDc8dsxgV0ZFxzd9ht0nL2aup5bSTwnc3mJoBO1cgR/o2An8ns8D3WaQ Hz8g== X-Gm-Message-State: ALoCoQlH8qUItkjQbiZ+/BkBDPBD88dySzDpBj/xUdZ0KRs6l2JXsUOCy9zcjyPSy8xzc1r9jXFU X-Received: by 10.98.2.213 with SMTP id 204mr42407816pfc.9.1448569049399; Thu, 26 Nov 2015 12:17:29 -0800 (PST) From: Bart Schaefer Message-Id: <151126121744.ZM5731@torch.brasslantern.com> Date: Thu, 26 Nov 2015 12:17:44 -0800 In-Reply-To: <56574625.308@eastlink.ca> Comments: In reply to Ray Andrews "convert sed to zsh" (Nov 26, 9:49am) References: <56574625.308@eastlink.ca> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh Users Subject: Re: convert sed to zsh MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Nov 26, 9:49am, Ray Andrews wrote: } Subject: convert sed to zsh } } sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" } } Here's my candidate zsh: } } bar=$foo//$'\x1B'\[([0-9](#c0,2)(;[0-9](#c0,2))#)#[mGK]/} That's a parse error, you're missing the opening curly brace. You can write $'\x1B' as $'\e' for clarity. Why change {1,2} in sed to (#c0,2) in zsh? (#c1,2) should work. } ... so far it's working, but I'm nervous about it. In another context } it seems I have to backslash the semi-colon, but here it seems ok either } way, but of course it should be one or the other. "Of course"? The reason both ';' and '\;' work there has to do with the properties of patterns rather than the properties of semicolons. Semicolon is a command terminator but otherwise is not special, so you need to protect a literal semicolon only from command parsing [such as inside $(...)]. } The 'sed' is of course the kosher way (I believe) of removing color } codes and various other escapes like "\e[K" that seem to hang around } colorized output of 'grep' and so on. I'm not quite an expert on color codes but the zsh expression should do the same as the sed (modulo 1,2 vs. 0,2 as noted and assuming you have extendedglob set). I do know that there are other escapes (cursor movements, overstriking, etc.) that won't match this expression, but probably you never encounter those in the usage you expect.