Understanding Patterns and Actions
An awk
pattern is simply the text or the regular expression upon which an action will operate. The source can be either a plain text file or the output of another program. To begin, let’s dump the entire contents of the /etc/passwd
file to the screen, like so:
[donnie@fedora ~]$ awk '{print $0}' /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
. . .
. . .
donnie:x:1000:1000:Donald A. Tevault:/home/donnie:/bin/bash
systemd-coredump:x:986:986:systemd Core Dumper:/:/usr/sbin/nologin
systemd-timesync:x:985:985:systemd Time Synchronization:/:/usr/sbin/nologin
clamupdate:x:984:983:Clamav database update user:/var/lib/clamav:/sbin/nologin
setroubleshoot:x:983:979:SELinux troubleshoot server:/var/lib/setroubleshoot:/usr/sbin/nologin
[donnie@fedora ~]$
In this command, the {print $0}
part is the action, which must be surrounded by a pair of single quotes. The $
designates which field to print. In this...