awk

Every program has a structure of:

pattern { action }

Print first column

$ awk '{print $1}'

Remove first column

$ awk '{ $1=""; print }'   # remove first column
$ awk '{ $3=""; print }'   # remove third column

Set multiple columns to same value

$ awk '{ $1=$2=$3=""; print }'

Execute system command

Sometimes you want to run a shell command on a value. Arguments can be passed by awk by setting the variable after it. The system call returns the status code from the command run:

$ awk '{ system("printf " $7); print }'

If, however, you want to capture the system output do:

awk '{
  cmd="printf %02d " $7
  while (cmd | getline line) {
    $7=line
  }
  close(cmd)
  print
}

See Also

results matching ""

    No results matching ""