Announcement

Collapse
No announcement yet.

awk problems--2 machines

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    awk problems--2 machines

    #!/bin/ksh
    #{for (i = 1; i <= 10; i++)
    # print i*5
    #}

    #using awk on win pc
    #the above will work but i have to hit enter key for it to begin and it prints a blank first
    #and then finishes but doesn't return to the terminal command line.
    #[b]this is on my win pc machine.on my kubuntu machine i receive an #error
    #"syntax error near unexpected token 'i'". it worked once and did not have
    #the problems---i can't remember how i did it---senility!!!!
    $i*5--as suggested does not work.don'really need the $.


    #!/bin/ksh
    {for (i =1; i <=NF; i++)
    print $i
    }


    this works fine! using awk -f progfile file and works on both machines..
    on my win pc i have only ksh.

    #2
    Re: awk problems--2 machines

    hi,
    It's been a while since I've scripted with AWK, but I believe that in your first example, it should be

    Code:
    print $i*5
    Note the $
    Registered Linux user #346571

    Comment


      #3
      Re: awk problems--2 machines

      Originally posted by desanti

      #!/bin/ksh
      {for (i =1; i <=NF; i++)
      print $i
      }

      this works fine! using awk -f progfile file and works on my linux pc with bash.
      on my win pc i have only ksh.
      Hmm...

      Code:
      #!/usr/bin/awk -f
      
      BEGIN{
       # at this moment NF is zero/undefined since here is no input was made
       # so we get one line of your wish
       getline;
       # then we use your code
       for (i =1; i <=NF; i++) { print $i }
       # now we should return to command line
       exit;
      }
      I suggest to `man awk`

      Comment


        #4
        Re: awk problems--2 machines

        The solution,at least on my pc's,was to insert BEGIN {.

        Comment


          #5
          Re: awk problems--2 machines

          Glad you got it working. Sorry the $ didn't help.
          Registered Linux user #346571

          Comment

          Working...
          X