awk2

条件式

{
  print NR ":" $0
  if (NR % 5 == 0){
   print "--------"
  }
}

forループ

{
 print("%-12s %5d", $1, $3)

 for (i = 0; i < int($3/10); i++){
 printf("*")
 }
 printf("\n")
}

配列

BEGIN{
  sales[1] = 200
  sales[2] = 120
  sales[3] = 50
  print sales[3]

  color = "yellow red blue"
  split(color, colors)
  print colors[3]
}

配列

{
  sales[$1] += $3
}
END {
  for (name in sales){
   print name ":" sales[name]
  }
}

関数の作り方

function getRate(n){
  return int(n / 100) * 0.1
}

{
printf("%-12s %5d rate:%0.1f\n", $1, $3, getRate($3))
}