Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.shell Subject: Re: help me do grep Message-ID: <1991Feb25.220449.19719@athena.mit.edu> Date: 25 Feb 91 22:04:49 GMT References: Sender: news@athena.mit.edu (News system) Distribution: comp Organization: Massachusetts Institute of Technology Lines: 32 You could do something like this: #!/bin/sh if [ $# -ne 2 ]; then echo "Usage: $0 pattern filename" exit 1 fi AWK='BEGIN { doprint = 0 record = "" } /\/\/\// { if (doprint) { printf("%s", record) } record = "" doprint = 0 next } /'$1'/ { doprint = 1 } { record = record $0 "\n" }' awk "$AWK" $2 If you only want to compare your pattern to a certain line of the entry, then you can count entry lines as you go along and only set doprint to true if the pattern matches *and* the current line number is the line of the entry against which you want to compare. -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710 Brought to you by Super Global Mega Corp .com