To provide this filtering using AWK, we will pipe the data from lastlog directly to awk. We will make use of a simple control file, initially providing the horizontal filtering or reducing the rows that we see. First, the command pipeline will be as simple as the following command example:
$ lastlog | awk -f lastlog.awk
Of course, the complexity is abstracted from the command line and concealed within the control file that we use. Initially, the control file is kept simple and reads as follows:
!(/Never logged in/ || /^Username/ || /^root/) { print $0; }
The range is set up as we have seen previously and precedes the main code block. Using the exclamation mark in front of the parentheses negates or reverses the selected range. The double vertical bar acts as a logical OR. We do not include lines that contain Never logged in, nor do we include lines that start with Username. This removes the header-line that is printed by lastlog. Finally, we exclude the root account from the display. This initiates the rows that we work with and the main code block will print those lines.