grep, etc

Jay R. Ashworth jra at baylink.com
Fri Aug 13 21:54:13 PDT 2004


On Wed, Aug 11, 2004 at 03:30:40PM -0400, Fairlight wrote:
> The honourable and venerable Robert Pulliam M.D. spoke thus:
> >     I have created a file using the export commant in filepro.  It is text with a newline record seperator.  the file looks like this:
> > 
> > ISA*00000089** *
> > CLM*inv123456*a*b*c         -213
> > SV1*23456*25*A*B            -214
> > 
> > i WANT TO BE ABLE TO VIEW A RANGE OF LINE USING GREP, MORE OR AWK.   IS THIS POSSIBLE.   IE FROM -213 TO -216
> 
> No, but you can view a range like this:
> 
> tail +213 filename |head -4
> 
> That would give you 213-216.

Actually, newer greps (GNUer greps?) do permit you to specify a window
of context around the matched line; in particular, GNU grep (found on
my RedHat 7.3 Linux, and likely most others, supports the -A and -B
options for this.

> Now if you need to always view the same window size but the specific data
> starts in one place and you need to combine grep's functionality with
> multi-line views, you could try something like:
> 
> tail +`grep -n unique_pattern /path/to/data |awk -F: '{print $1}' |head -1` \
> /path/to/data | head -5

And now you understand why.  :-)

Cheers,
-- jra
-- 
Jay R. Ashworth                                                jra at baylink.com
Designer                          Baylink                             RFC 2100
Ashworth & Associates        The Things I Think                        '87 e24
St Petersburg FL USA      http://baylink.pitas.com             +1 727 647 1274

	"You know: I'm a fan of photosynthesis as much as the next guy,
	but if God merely wanted us to smell the flowers, he wouldn't 
	have invented a 3GHz microprocessor and a 3D graphics board."
					-- Luke Girardi


More information about the Filepro-list mailing list