Thread: awk problem

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    330

    awk problem

    I have the following awk script that sets a flag to 1 if Left is matched on a line, until that time left == 0. Then whenever the first field ($1) is between 1 and 100 I want to print $1 and if it is left or not. But whatever I try the value of $left is always the same as $1.

    Does anybody know what I'm doing wrong?

    Code:
    $3 ~ /Left/  { left=1 }
    
    $1 >= 1 && $1 <= 100 \
    {
      printf " ""%d"" ""%d"">\n", $1, $left
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    $left prints $1

    You're thinking of Perl, which has $ in all scalar variable references

    In awk, it's
    printf " ""%d"" ""%d"">\n", $1, left
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    ah yes that works, thanks

    I wasnt thinking of perl though since I never used it
    Last edited by KIBO; 01-23-2007 at 08:57 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM