Skip to content

Latest commit

 

History

History
55 lines (42 loc) · 1.18 KB

awk.md

File metadata and controls

55 lines (42 loc) · 1.18 KB

awk: Pattern scanning and processing

The awk command allows for complex pattern scanning and processing. awk is an entire programming language allowing complex interpreted programs. One of its most powerful features is the print function to reformat the output of other commands. This is the form we will focus on for this section. It uses the following format:

awk [ -Fcolumn_separator] '{print format_string}'

where column_separator is the character separating columns in the input and format_string is the new format of the output. By default, the column separator is a space or a tab character. The variables $1, $2, ... are output fields to put in the format string.

Example use:

date

which will have output like this:

Fri Apr 21 04:35:19 PM UTC 2023
date | awk '{print $2 $3}'

which will have output like this:

Apr21
date | awk '{ print $2" "$3}'

which will have output like this:

Jul 28
who

which will have output like this:

pulsys   pts/0        2023-04-21 16:35 (172.20.217.223)
who | awk '{print $1}'

which will have output like this:

pulsys