getline help 
Author Message
 getline help

Hello,

      I just wrote a script that uses getline function in a while
loop to read a file for processing.....

     while ( (getline < CMDFILE) > 0 )
     {

        .........

     }

     Everytime I run this script it waits for user input before it
process the rest of the file....
     Is there anyway i could skip the user input and have it process
the file immediately??????

Any help will be greatly appreciated...

Thanks,

Gabriel



Mon, 30 Apr 2001 03:00:00 GMT  
 getline help
Question:

What is the value of CMDFILE (if not assigned, then this is probably the
source of your problem). CMDFILE shoud evaluate to a file which can be
opened for reading. It's not clear from the sample code that you provided
whether this variable is set before being used.

Your code should read something like:

{
CMDFILE="MyInputFile.txt"
while ((getline < CMDFILE) > 0) {
# do stuff here

Quote:
}
close(CMDFILE)
}

--
Please remove the UPPERCASE characters from my e-mail address for the real
thing
Quote:

>Hello,

>      I just wrote a script that uses getline function in a while
>loop to read a file for processing.....

>     while ( (getline < CMDFILE) > 0 )

>        .........

>     }

>     Everytime I run this script it waits for user input before it
>process the rest of the file....
>     Is there anyway i could skip the user input and have it process
>the file immediately??????

>Any help will be greatly appreciated...

>Thanks,

>Gabriel




Mon, 30 Apr 2001 03:00:00 GMT  
 getline help

Thanks for responding Cesar...

I do have my CMDFILE defined.....

BEGIN {
  FS = ":"; count = 0 ; CMDFILE = "/tmp/abc.log"

Quote:
}

{

        system("clear")
        while ((getline < CMDFILE) > 0)
        {
          .......
        }
        close(CMDFILE)

Quote:
}

anymore ideas??????

Thanks,
Gabriel

Quote:

> Question:
> What is the value of CMDFILE (if not assigned, then this is probably the
> source of your problem). CMDFILE shoud evaluate to a file which can be
> opened for reading. It's not clear from the sample code that you provided
> whether this variable is set before being used.
> Your code should read something like:
> {
> CMDFILE="MyInputFile.txt"
> while ((getline < CMDFILE) > 0) {
> # do stuff here
> }
> close(CMDFILE)
> }
> --
> Please remove the UPPERCASE characters from my e-mail address for the real
> thing

> >Hello,

> >      I just wrote a script that uses getline function in a while
> >loop to read a file for processing.....

> >     while ( (getline < CMDFILE) > 0 )

> >        .........

> >     }

> >     Everytime I run this script it waits for user input before it
> >process the rest of the file....
> >     Is there anyway i could skip the user input and have it process
> >the file immediately??????

> >Any help will be greatly appreciated...

> >Thanks,

> >Gabriel


--

================================================================================  
                            HUGHES AIRCRAFT COMPANY
================================================================================                        

                                Gabriel N. Tan



                   PHONE:   (714)446-2623

================================================================================



Mon, 30 Apr 2001 03:00:00 GMT  
 getline help
It looks like the construction is correct. So it may be one of several
things.

1. Implementation of getline in your awk interpreter (?)
2. contents of /tmp/abc.log
3. ???

Have you tried to put in some debugging print commands to see if at least
one line is read from /tmp/abc.log and if so, where does it stop to ask for
your input?

You might also try

while ((getline nextLine < CMDFILE) > 0) {
# process nextLine as if it was $0

Quote:
}

I don't know if that will help you.

One last thing you could try is rather than trying to get the return value
of getline and comparing it at the same time in the while condition, try
this:

returnCode = getline < CMDFILE
while (returnCode > 0) {
# some processing
    returnCode = getline < CMDFILE

Quote:
}

Good luck,

Cesar
--
Please remove the UPPERCASE characters from my e-mail address for the real
thing

Quote:

>Thanks for responding Cesar...

>I do have my CMDFILE defined.....

>BEGIN {
>  FS = ":"; count = 0 ; CMDFILE = "/tmp/abc.log"
>}

>{

>        system("clear")
>        while ((getline < CMDFILE) > 0)
>        {
>          .......
>        }
>        close(CMDFILE)

>}

>anymore ideas??????

>Thanks,
>Gabriel


>> Question:

>> What is the value of CMDFILE (if not assigned, then this is probably the
>> source of your problem). CMDFILE shoud evaluate to a file which can be
>> opened for reading. It's not clear from the sample code that you provided
>> whether this variable is set before being used.

>> Your code should read something like:

>> {
>> CMDFILE="MyInputFile.txt"
>> while ((getline < CMDFILE) > 0) {
>> # do stuff here
>> }
>> close(CMDFILE)
>> }

>> --
>> Please remove the UPPERCASE characters from my e-mail address for the
real
>> thing

>> >Hello,

>> >      I just wrote a script that uses getline function in a while
>> >loop to read a file for processing.....

>> >     while ( (getline < CMDFILE) > 0 )

>> >        .........

>> >     }

>> >     Everytime I run this script it waits for user input before it
>> >process the rest of the file....
>> >     Is there anyway i could skip the user input and have it process
>> >the file immediately??????

>> >Any help will be greatly appreciated...

>> >Thanks,

>> >Gabriel

>--

>===========================================================================
=====
>                            HUGHES AIRCRAFT COMPANY
>===========================================================================
=====

>                                Gabriel N. Tan



>                   PHONE:   (714)446-2623

>===========================================================================
=====



Mon, 30 Apr 2001 03:00:00 GMT  
 getline help

Quote:

> Hello,

>       I just wrote a script that uses getline function in a while
> loop to read a file for processing.....

>      while ( (getline < CMDFILE) > 0 )
>      {

>         .........

>      }

>      Everytime I run this script it waits for user input before it
> process the rest of the file....
>      Is there anyway i could skip the user input and have it process
> the file immediately??????

> Any help will be greatly appreciated...

> Thanks,

> Gabriel


Your code fragment really doesn't show your problem very well.  What
are you really trying to do?  Does your script just process
the file named in CMDFILE?  Are you using a standalone script?

That would be my guess and I would guess your code looks like:

#!/usr/bin/awk -f
{
...
while ( (getline < CMDFILE) > 0 )
   {

      .........

   }
exit

Quote:
}

[ If you had given more info,  I wouldn't have to guess]

If that's the case,  you can either:

#!/usr/bin/awk -f
BEGIN {
while ( (getline < CMDFILE) > 0 )
   {

      .........

   }
exit

Quote:
}

or stuff the CMDFILE name into the ARGUMENT list.  Then you won't
need getline or a while loop:

#!/usr/bin/awk -f
BEGIN {
ARGV[1] = "cmdfile"
ARGC    = 2

Quote:
}

pattern { action ... }
pattern { action ... }
pattern { action ... }

Opinions expressed herein are my own and may not represent those of my employer.



Mon, 30 Apr 2001 03:00:00 GMT  
 getline help

Quote:

>    I just wrote a script that uses getline function in a while
> loop to read a file for processing.....

>    while ( (getline < CMDFILE) > 0 )
>    {
>        .........
>    }

>    Everytime I run this script it waits for user input before it
> process the rest of the file....
>    Is there anyway i could skip the user input and have it process
> the file immediately??????

Put the while loop in a BEGIN rule:

BEGIN {
    ...
    while ((getline <CMDFILE) > 0) {
        ...
    }
    ...

Quote:
}

Think carefully about what happens when you put the 'while (getline)'
loop inside the intrinsic read-records-until-end-of-input loop of awk,
like this:

{
    ...
    while ((getline <CMDFILE) > 0) {
        ...
    }
    ...

Quote:
}

This will read all of the records in the file CMDFILE each time a
record is read from the files specified on the command line, or from
standard input if none were specified. This explains the "wait[ing]
for user input" behavior that you describe.

--
Jim Monty

http://www.primenet.com/~monty/
Tempe, Arizona USA



Mon, 30 Apr 2001 03:00:00 GMT  
 getline help

Jim, you are right. after moving the while loop within the
Begin rule. The script skipped the user input alltogether
which is what I wanted........

Thanks a million to everyone  who offered their inputs.......

Regards,

Gabriel

Quote:


> >    I just wrote a script that uses getline function in a while
> > loop to read a file for processing.....

> >    while ( (getline < CMDFILE) > 0 )
> >    {
> >        .........
> >    }

> >    Everytime I run this script it waits for user input before it
> > process the rest of the file....
> >    Is there anyway i could skip the user input and have it process
> > the file immediately??????
> Put the while loop in a BEGIN rule:
> BEGIN {
>     ...
>     while ((getline <CMDFILE) > 0) {
>         ...
>     }
>     ...
> }
> Think carefully about what happens when you put the 'while (getline)'
> loop inside the intrinsic read-records-until-end-of-input loop of awk,
> like this:
> {
>     ...
>     while ((getline <CMDFILE) > 0) {
>         ...
>     }
>     ...
> }
> This will read all of the records in the file CMDFILE each time a
> record is read from the files specified on the command line, or from
> standard input if none were specified. This explains the "wait[ing]
> for user input" behavior that you describe.
> --
> Jim Monty

> http://www.primenet.com/~monty/
> Tempe, Arizona USA

--

================================================================================  
                            HUGHES AIRCRAFT COMPANY
================================================================================                        

                                Gabriel N. Tan



                   PHONE:   (714)446-2623

================================================================================



Tue, 01 May 2001 03:00:00 GMT  
 getline help


   >Hello,
   >I just wrote a script that uses getline function in a while
   >loop to read a file for processing.....
   >while ( (getline < CMDFILE) > 0 )
   >{
   >.........
   >}
   >Everytime I run this script it waits for user input before it
   >process the rest of the file....
   >Is there anyway i could skip the user input and have it process
   >the file immediately??????
Does your script get input only from CMDFILE, or is there a filename in the
command line?  If there is no filename in the command line, you should use
a BEGIN block that ends with "exit".

Net-Tamer V 1.08X - Test Drive



Tue, 01 May 2001 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. newbie help - getline problem

2. simplify a pipe into a getline

3. getline and loop questions

4. getline into a variable from a pipe, 3.1.1 to 3.1.2

5. Undoing getline function

6. How to use getline?

7. awk lookup problem using getline

8. problem with multiple getline

9. awk: getline of a file

10. problem with multiple getline

11. GAWK 3.1 getline Timeout

12. ???Using Getline in a While Loop???

 

 
Powered by phpBB® Forum Software