Xref: utzoo comp.unix.wizards:8936 comp.unix.questions:7311 Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!ncar!groucho.ucar.edu!russ From: russ@groucho.ucar.edu (Russ Rew) Newsgroups: comp.unix.wizards,comp.unix.questions Subject: Re: grep replacement Summary: "grep with context" can be done with awk Message-ID: <292@ncar.ucar.edu> Date: 29 May 88 21:45:49 GMT References: <7882@alice.UUCP> <5630@umn-cs.cs.umn.edu> <6866@elroy.Jpl.Nasa.Gov> <2312@bgsuvax.UUCP> Sender: news@ncar.ucar.edu Reply-To: russ@groucho.UCAR.EDU (Russ Rew) Organization: UNIDATA Project/NCAR, Boulder, CO Lines: 14 I also recently had a need for printing multi-line "records" in which a specified pattern appeared somewhere in the record. The following short csh script uses the awk capability to treat whole lines as fields and empty lines as record separators to print all the records from standard input that contain a line matching a regular specified as an argument: #!/bin/csh -f awk 'BEGIN {RS = ""; FS = "\n"; OFS = "\n"; ORS = "\n\n"} /'"$1"'/ {print} ' Russ Rew * UCAR (University Corp. for Atmospheric Research) PO Box 3000 * Boulder, CO 80307-3000 * 303-497-8845 russ@unidata.ucar.edu * ...!hao!unidata!russ