For Programmers: Free Programming Magazines  


Home > Archive > AWK > September 2004 > Skipping the 1st occurence of a search/only printing the nth?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Skipping the 1st occurence of a search/only printing the nth?
groblela

2004-09-10, 3:55 pm

I need to process a search of an array, locating the nth occurrence of the
search and only printing that particular record.
The following will locate the criteria and print, but only the first
occurence.

nawk '$1 == "RTOUT" {print $0, exit}' ${inputF} > ${outputF}

Any help on skipping the first occurence, locating the nth and only
printing that record?

Any suggestions would be appreciated,
groblela

William Park

2004-09-10, 3:55 pm

groblela <lee.grobleski@nospam.wpafb.af.mil> wrote:
> I need to process a search of an array, locating the nth occurrence of the
> search and only printing that particular record.
> The following will locate the criteria and print, but only the first
> occurence.
>
> nawk '$1 == "RTOUT" {print $0, exit}' ${inputF} > ${outputF}
>
> Any help on skipping the first occurence, locating the nth and only
> printing that record?
>
> Any suggestions would be appreciated,
> groblela


Use a counter. If counter reaches 'n', then print.

--
William Park <opengeometry@yahoo.ca>
Open Geometry Consulting, Toronto, Canada
Brian Inglis

2004-09-10, 3:55 pm

On Fri, 10 Sep 2004 10:29:18 -0400 in comp.lang.awk, "groblela"
<lee.grobleski@nospam.wpafb.af.mil> wrote:

>I need to process a search of an array, locating the nth occurrence of the
>search and only printing that particular record.
>The following will locate the criteria and print, but only the first
>occurence.
>
>nawk '$1 == "RTOUT" {print $0, exit}' ${inputF} > ${outputF}
>
>Any help on skipping the first occurence, locating the nth and only
>printing that record?


nawk -vN=5 '$1 == "RTOUT" { if (++cnt == N) { print $0; exit } }'

--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada

Brian.Inglis@CSi.com (Brian[dot]Inglis{at}SystematicSW[dot]a
b[dot]ca)
fake address use address above to reply
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com