Re: How can I search only a portion of a file?

From: Fabrice Guerini (fabrice@BLUEMARTINI.COM)
Date: Wed Jul 17 2002 - 15:40:57 EDT


At 12:11 PM 7/17/2002, Ignacio Vidal wrote:
>Maybe using awk with an internal variable that counts the occurence of
>"A" until occurence of "> uniquestringABC" ?

Sure, like so:

         awk '/uniquestringABC/ { exit; }
              /^A$/ { print; }' file

And how about:

         sed -ne '/uniquestringABC/q' -e '/^A$/p' file | wc -l

> > De: Taylor, David [mailto:DTaylor@WBMI.COM]
> > Enviado el: miércoles, 17 de julio de 2002 15:03
> > Para: aix-l@Princeton.EDU
> > Asunto: How can I search only a portion of a file?
> >
> >
> > Hi *
> >
> > Let's say that I have a file with the following contents:
> >
> > --------------------------------------
> > A
> > A
> > B
> > A
> > uniquestringABC
> > A
> > B
> > B
> > A
> > -------------------------------------
> >
> > How can I count the number of instances of 'A' up to the
> > occurrence of
> > uniquestringABC? How about the instances ~after~ uniquestringABC?
> >
> > There has to be an easier way than splitting the file at
> > uniquestringABC and
> > counting the separate files.
> >
> > TIA
> >
> > David
> >
> > David Taylor
> > Senior Software Systems Engineer
> > West Bend Mutual Insurance
> > (262) 335-7077
> > dtaylor@wbmi.com

+===========================================================+
| Fabrice "Script It!" Guerini Blue Martini Software, Inc. |
| Senior Operations Engineer 2600 Campus Drive |
| Tel: (650) 356-7576 San Mateo, CA 94403-2522 |
| Fax: (650) 356-4001 www.bluemartini.com |
+===========================================================+



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:04 EDT