Path: utzoo!utgpu!attcan!uunet!mcvax!ukc!stc!datlog!dlhpedg!cl
From: cl@datlog.co.uk (Charles Lambert)
Newsgroups: comp.sources.wanted
Subject: Re: A column oriented (as in cut) grep command
Summary: Do it with awk(1)
Message-ID: <871@dlhpedg.co.uk>
Date: 28 Sep 88 14:49:52 GMT
References: <1725@teksce.SCE.TEK.COM>
Sender: news@dlhpedg.co.uk
Reply-To: cl@datlog.co.uk (Charles Lambert)
Organization: FSD@Data Logic Ltd, Queens House, Greenhill Way, Harrow, London.
Lines: 22

I'm posting this, rather than mailing to the originator,  because you awk(1)
experts may want to correct it.

In article <1725@teksce.SCE.TEK.COM> johnhi@teksce.SCE.TEK.COM (John Higley) writes:
>
>Does anybody know of a version of grep that can be limited to certain columns
>in a text file?  What I am thinking about is something that would have
>options such as -c and -f in the cut command.
>
>That reminds me, it would also be nice if it could tell the line number that
>the match was found on.

"Awk" is designed to do this kind of job.  An awk(1) command to find a pattern
in column two and print the line numbers would look something like this:

	awk '$2 ~ /egrep-pattern/ {printf "%d: ", NR; print}' file

Putting this in a shell script with appropriate argument-passing would give you
the tool you need.

----------
Charlie