terminal.cab

All commands

awk

Topic: Text

Program: awk

Processes text line by line with a small program.

Package: awk

Usage

awk [-F FS] [-v VAR=VALUE] [-f PROGFILE | 'PROGRAM'] [VAR=VALUE | FILE]...

Description

Run the PROGRAM on every line of the FILEs (or of the keyboard or pipe). A program is a list of PATTERN { ACTION }: the ACTION runs for each line that matches the PATTERN. $1, $2, ... are the fields of the line, $0 is the whole line, NR counts lines, NF counts fields. BEGIN { ... } runs before the first line, END { ... } after the last.

Options in the simulator

1 more options of the real program, not in the simulator yet
  • -W needs a value not in the simulator yet

    On a real system -W sets options special to mawk (for example -W version or -W interactive).

Examples

From the lesson Evaluating columns with awk
awk '{print $1}' logs/app.log.1
23:40:12
23:45:31
23:52:08
23:59:58
awk '{print $2, $NF}' logs/app.log.1
INFO 77ms
INFO entries
WARN 1320ms
INFO rotated

Try it in the terminal

Where you learn it

Lessons

All commands