Field processing with awkCommand line · 0/4 steps

Print a fieldstep 1 of 4 · intermediate

Support

The command is shown. Click it to run, or type your own.

By the end of this lesson you can
  • Print a chosen field with awk '{ print $2 }'
  • Keep only rows that match a condition ($4 == "HIGH")
  • Accumulate a running total and print it in an END block
  • Filter rows numerically, e.g. $3 > 300

Before you startColumns with cut and filtering with grep; awk generalises both.

In awk, $2 is the second field of the current line. { print $2 } runs on every line.

Print the gene column of variants.tsv with awk.

chr1$1
BRCA1$2
missense$3
HIGH$4
awk splits each line into numbered fields, so $1 is the first column, $2 the second, and so on.
Key concept

Every awk rule has the shape condition { action }. Omit the condition and the action runs on every line; omit the action and matching lines are printed. That one idea, a pattern paired with what to do, is the whole language in miniature.

workspace · terminal

Type a command, or click the suggested one. ↑/↓ recall history, Tab completes file names. New to this? Hit Explain this command to see it in plain English.

…
workspace/shared/data0 files
Booting the WebAssembly runtime…
Command line0 / 4 stepsStep 1WASM shell