Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

scan

macrumors 6502
Original poster
Oct 24, 2005
344
0
is there a way, using awk, to print fields x - x (ie $3 - $10)?
 
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.
 
OutThere said:
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.


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
 
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.
 
PatrickF said:
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.

yeah thats what I ended up doing. I thought maybe there was a built in way to do this. thanks.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.