For Programmers: Free Programming Magazines  


Home > Archive > AWK > February 2007 > body pointer









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 body pointer
ehabaziz2001@gmail.com

2007-02-14, 3:57 am

How can I return the pointer of awk processing to the start of the
file if I used getline in the begin section ?

Begin {

getline
...
store some values
....

}

{

start processing the file from the beginning

}
End
{
}

Janis

2007-02-14, 3:57 am

On 14 Feb., 07:39, ehabaziz2...@gmail.com wrote:
> How can I return the pointer of awk processing to the start of the
> file if I used getline in the begin section ?


Provide your file argument twice to awk.

NR==FNR && NR==1 { ... ; nextfile } # first pass through file
# 'nextfile' is non-standard (gawk), otherwise use 'next'

{ ... } # next pass through the file


But you don't need to do that. Instead just avoid getline[*]...

NR==1 { ...
store some values
...
}

{
start processing the file from the beginning
...
}

Would be the awk'ish way to do that.

Janis

[*] Browse this newsgroup for an article about getline caveats (posted
by Ed Morton) to learn why to avoid getline.

>
> Begin {
>
> getline
> ..
> store some values
> ...
>
> }
>
> {
>
> start processing the file from the beginning
>
> }
>
> End
> {
>
> }



Ed Morton

2007-02-14, 7:57 am

Janis wrote:
> On 14 Feb., 07:39, ehabaziz2...@gmail.com wrote:
>
>
>
> Provide your file argument twice to awk.
>
> NR==FNR && NR==1 { ... ; nextfile } # first pass through file
> # 'nextfile' is non-standard (gawk), otherwise use 'next'
>
> { ... } # next pass through the file
>
>
> But you don't need to do that. Instead just avoid getline[*]...
>
> NR==1 { ...
> store some values
> ...
> }
>
> {
> start processing the file from the beginning
> ...
> }
>
> Would be the awk'ish way to do that.
>
> Janis
>
> [*] Browse this newsgroup for an article about getline caveats (posted
> by Ed Morton) to learn why to avoid getline.


http://tinyurl.com/yn9ka9
Sponsored Links







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

Copyright 2008 codecomments.com