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

  • Follow


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

0
Reply groblela 9/10/2004 2:29:18 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
0
Reply William 9/10/2004 2:37:51 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]ab[dot]ca)
    fake address		use address above to reply
0
Reply Brian 9/10/2004 4:16:46 PM

2 Replies
496 Views

(page loaded in 0.064 seconds)

Similiar Articles:












7/28/2012 6:27:34 PM


Reply: