awk Pipes
Pipes
AWK can receive input and send output to other commands via the pipe.
$ echo -e "1 2 3 5\n2 2 3 8" | awk '{print $(NF)}'
5
8
In this case, AWK receives output from the echo
command. It prints the values of last column.
$ awk -F: '$7 ~ /bash/ {print $1}' /etc/passwd | wc -l
3
Here, the AWK program sends data to the wc
command via the pipe. In the AWK program, we find out those users who use bash. Their names are passed to the wc
command which counts them. In our case, there are three users using bash.