Text and processing
The awk command
Processes text by columns and lets you filter and compute in one line.
Syntax
awk [-F sep] '{print $N}'Most useful options
-FSets the field separator$1..$NEach columnNRLine numberCopy-ready examples
$ awk '{print $1}' Documentos/tareas.txtThe first column$ awk -F : '{print $1}' /etc/passwdWith a colon separator$ awk '{print NR": "$0}' Documentos/tareas.txtNumber linesYou can try them in the browser terminal: it does not touch your computer.
Typical mistakes
- By default it splits on whitespace, not commas.
FAQ
Can awk add things up?
Yes: you can compute with the columns, e.g. sum field 3.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course