Forever & AlwaysLINUX COMMAND ATLAS

LINUX COMMAND ATLAS · COMMAND GUIDE

Linux awk command

Process text by fields and patterns; fields are separated by whitespace by default.

GNU Awk

Syntax

Command form
awk [OPTION]... 'PROGRAM' [FILE]...

Common options

5 options
OptionWhat it does
-F FS, --field-separator=FSSet the input field separator.
-v VAR=VALUEAssign a variable before the program runs.
-f FILERead the awk program from FILE.
-e PROGRAMAdd program source text.
-i FILELoad an awk extension library (gawk).

Usage examples

3 examples

Process text by fields and patterns; fields are separated by whitespace by default.

awk '{print $1}' access.log

Print the first colon-separated field.

awk -F: '{print $1}' /etc/passwd

Print the first and third fields where the third exceeds 100.

awk '$3 > 100 {print $1, $3}' scores.txt

Notes

awk implementations differ; extensions such as -i are specific to GNU awk. Quote programs to protect them from the shell.