Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Skipping the 1st occurence of a search/only printing the nth?
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


Report this thread to moderator Post Follow-up to this message
Old Post
groblela
09-10-04 08:55 PM


Re: Skipping the 1st occurence of a search/only printing the nth?
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

Report this thread to moderator Post Follow-up to this message
Old Post
William Park
09-10-04 08:55 PM


Re: Skipping the 1st occurence of a search/only printing the nth?
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

Report this thread to moderator Post Follow-up to this message
Old Post
Brian Inglis
09-10-04 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:10 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.