From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13028 invoked by alias); 16 Aug 2015 20:24:48 -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: 20418 Received: (qmail 1222 invoked from network); 16 Aug 2015 20:24:46 -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-Injected-Via-Gmane: http://gmane.org/ To: zsh-users@zsh.org From: Joep van Delft Subject: Re: Tip of the day: grep2awk zle function Date: Sun, 16 Aug 2015 22:24:33 +0200 Message-ID: <20150816222433.6ab324bf@xs4all.nl> References: <20150815010157.696d904b@xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: p54895423.dip0.t-ipconnect.de X-Newsreader: Claws Mail 3.12.0 (GTK+ 2.24.28; i686-pc-linux-gnu) On Sun, 16 Aug 2015 11:38:00 +0000 (UTC) zzapper wrote: > > Code, installation instructions, and some details can be found at > > https://github.com/joepvd/grep2awk.=20 > > Sounds interesting do you have any typical before & after examples? >=20 A yeah, examples make sense, thanks! After placing the file grep2awk in $zpath, type: % autoload -Uz grep2awk % zle -N grep2awk % bindkey "^X^A" grep2awk Then, if you press the key combination, the editing buffer will be searched for grep commands, and the buffer will have the grep part replaced by an awk command.=20 % grep 'there^here' %=C2=A0awk -- '/there\^here/ {print $0}' It works with pipes, subshells, et cetera (thanks to split-shell-arguments): % ps aux | grep kswap | sort % ps aux | awk -- '/kswap/ {print $0}' | sort The meat of this thing is in the transformation of BREs to EREs (when egrep or -E is not called):=20 % grep '^a^b\(c(\|d)e\)' file %=C2=A0awk -- '/^a\^b(c\(|d\)e)/ {print $0}' file Some options to grep will be translated to appropriate awk statements: % grep -vi 'not here' file % awk -- 'BEGIN{IGNORECASE=3D1}; !/not here/ {print $0}' file Kind regards, Joep