Re: read input from beginning at eof?



On Tue, 16 Jun 2009 08:36:38 -0700, sws_chen wrote:

Hello,
I am new at awk (and programming in general) and would greatly appreciate
your help. I am writing a code that needs to read through an input file
49 times. Is there a way so that once the program reads to the eof of the
input, it will start reading again from the beginning of the file? Or
maybe once it reaches the eof it could set could set current line to a
previous line 'x' lines above? I eagerly await an answer, thank you.
Steven

Unless the file is *huge*, it doesn't need to be read more thna once: read
it into and array and then read the array as many times as needed.

{
Array[NR] = $0
}
END{
for( x = 1; x <= 49; x++ ) {
for( y = 1; y <= NR; y++ ) do something with Array[ y ] and x
}
}

--
T.E.D. (tdavis@xxxxxxx)




.



Relevant Pages

  • read input from beginning at eof?
    ... I am new at awk (and programming in general) and would greatly ... I am writing a code that needs to read through ... an input file 49 times. ... Or maybe once it reaches the eof it could set ...
    (comp.lang.awk)
  • Seek Contract Programming Work - 17 Years Experience
    ... where I did nothing but debugging and optimization. ... electric keyboard), so I enjoy writing MIDI, audio and music applications. ... file format to the C++ API) for a financial firm in the Bahamas, ... to handle any sort of programming task. ...
    (comp.programming)
  • Seek Contract Programming Work - 17 Years Experience
    ... where I did nothing but debugging and optimization. ... electric keyboard), so I enjoy writing MIDI, audio and music applications. ... file format to the C++ API) for a financial firm in the Bahamas, ... to handle any sort of programming task. ...
    (comp.lang.java.programmer)
  • Intro to Writing "Good" Code
    ... Intro to Writing "Good" Code ... The first rule of programming is "take ... Readability: Eventually somebody is going to have to ... The reason for this is that the ...
    (comp.programming)
  • Re: Puppy Mastiff wants to Nip at Faces
    ... in my first college textbook on structured programming. ... they did was loop through an array to show how you could easily ... design, PIC code, and real time programming. ...
    (rec.pets.dogs.behavior)