awk command

Discussion in 'Mac Basics and Help' started by scan, Jul 19, 2006.

  1. scan macrumors 6502

    Joined:
    Oct 24, 2005
    #1
    is there a way, using awk, to print fields x - x (ie $3 - $10)?
     
  2. Sdashiki macrumors 68040

    Sdashiki

    Joined:
    Aug 11, 2005
    Location:
    Behind the lens
  3. OutThere macrumors 603

    OutThere

    Joined:
    Dec 19, 2002
    Location:
    NYC
    #3
    How about giving us a little more, um, detail?

    It's pretty hard to help you when you don't tell us what you're trying to do.
     
  4. Mitthrawnuruodo Moderator emeritus

    Mitthrawnuruodo

    Joined:
    Mar 10, 2004
    Location:
    Bergen, Norway
  5. scan thread starter macrumors 6502

    Joined:
    Oct 24, 2005
    #5

    awk is a command in unix. you can print fields/columns of a files by referring to them as $1 for field 1, $2 for field two, etc.

    instead of saying I want to print $1, $2, $3... i just want to print a range
    ie: fields 1-5
     
  6. PatrickF macrumors 6502

    Joined:
    Feb 16, 2006
    Location:
    Blighty
    #6
    You can do this with a for loop in awk. Try the following code:

    Code:
    {
      for (i = 1; i <= 5; i++)
      {
        printf "%s ", $i
      }
      printf "\n"
    }
    
    That will print fields 1 to 5 and add a newline after each line.
     
  7. scan thread starter macrumors 6502

    Joined:
    Oct 24, 2005
    #7
    yeah thats what I ended up doing. I thought maybe there was a built in way to do this. thanks.
     
  8. d wade macrumors 65816

    d wade

    Joined:
    Jun 27, 2006
    Location:
    Boca Raton, FL
    #8
    my thoughts exactly, lol
     

Share This Page