tobold.org

correct • elegant • free

△ comp.unix.shell △

◅ ' problem

I need to get hold of a simple Unix Shell source code ▻

Help on a grep command

In article <7va5k2$rdl@news-central.tiac.net>,
Charles Demas <demas@sunspot.tiac.net> wrote:
>Doing it in one pass is not as easy, IMO.  YMMV

I'm no awk expert, but if you don't mind about repeats for overlapping
blocks it's very easy to do in one pass.

    awk 'l ~ /pattern/ { print lll;print ll;print l;print nl;print nnl } { lll = ll; ll = l; l = nl; nl = nnl; nnl = $0 }' file

Tim.
--
Tim Goodwin   | "People think [ W. Gibson is ] hi-tech because his prose
Leicester, UK | is as pleasant to read as a C++ program." -- JT

Original headers:

From: tjg@star.le.ac.uk (Tim Goodwin)
Newsgroups: comp.unix.shell
Subject: Re: Help on a grep command
Date: 29 Oct 1999 12:37:09 +0100
Organization: University of Leicester, UK
Message-ID: <7vc0tr$28k$1@ltpcg.star.le.ac.uk>
References: <3816F4E4.9D52BEFB@abz.nl> <381839C2.86C67F4D@abz.nl>
  <7va5k2$rdl@news-central.tiac.net>

△ comp.unix.shell △

◅ ' problem

I need to get hold of a simple Unix Shell source code ▻