Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Tip of the day: grep2awk zle function
- X-seq: zsh-users 20418
- From: Joep van Delft <joepvandelft@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Tip of the day: grep2awk zle function
- Date: Sun, 16 Aug 2015 22:24:33 +0200
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20150815010157.696d904b@xs4all.nl> <XnsA4F880855A40Ddavidrayninfocouk@80.91.229.13>
On Sun, 16 Aug 2015 11:38:00 +0000 (UTC)
zzapper <david@xxxxxxxxxxxxxx> wrote:
> > Code, installation instructions, and some details can be found at
> > https://github.com/joepvd/grep2awk.
>
> Sounds interesting do you have any typical before & after examples?
>
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.
% grep 'there^here'<CTRL-X><CTRL-A>
% awk -- '/there\^here/ {print $0}'
It works with pipes, subshells, et cetera (thanks to
split-shell-arguments):
% ps aux | grep kswap | sort<CTRLX><CTRL-A>
% 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):
% grep '^a^b\(c(\|d)e\)' file<CTRL-X><CTRL-A>
% awk -- '/^a\^b(c\(|d\)e)/ {print $0}' file
Some options to grep will be translated to appropriate awk statements:
% grep -vi 'not here' file <CTRLX><CTRL-A>
% awk -- 'BEGIN{IGNORECASE=1}; !/not here/ {print $0}' file
Kind regards,
Joep
Messages sorted by:
Reverse Date,
Date,
Thread,
Author