awk 3-tuple expression, if...else structure can be overridden with a 3-tuple expression
[Email protected]:~/linux/awk$awk-V fs=":" '{type=$3>=1000? " Normal user ":" System User ";p rint $1,type}'/etc/passwdroot System User Daemon system User Bin system User sys system userSyncSystem User Games System userMansSystem UsersLPSystem User mail system User News system user UUCP system User Proxy system user www-Data System User backup system User list system user IRC system user gnats system user Nobody ordinary user systemd-timesync System User Systemd-Network System User Systemd-Resolve System User Systemd-bus-Proxy System User syslog system User _apt System User Messagebus System User Uuidd System User LIGHTDM System User Whoopsie system user Avahi-AUTOIPD System User Avahi System user DNSMASQ System User Colord System user speech-Dispatcher System User Hplip System User kernoops System User Pulse System User Rtkit System User saned System User Usbmux System user ghostwu Normal user MySQL system user Guest-Iilhaz System User Smmta System user Smmsp system User
Count the number of ordinary users and system users
[Email protected]:~/linux/awkawk -v fs=":"'{$3>=1000 ? user++: snumber++} end{print "user number:", User, "system number:", snumber}' /etc/passwd
2
awk Prints Parity lines
1. In awk, if the action of the pattern is omitted, the default action is to print the entire line when the current row satisfies the pattern, which is {print $}
2. In awk, 0 or an empty string means "false", a non-0 value or a non-empty string means "true", when the pattern is false, the action does not execute, when the pattern is true, the action executes
[Email protected]:~/linux/awkawk'i=!i'1 3 5 7 9one line
When awk scans the first row, the I variable is initialized to null, the inverse becomes true, the whole pattern is true, so the first line is printed, the second line is reversed, and the inverse assignment becomes false .... And so on
[Email protected]:~/linux/awkawk'{i=!i;print i;} ' 101010101 0 1
Reverse again, print the even line
[Email protected]:~/linux/awkawk'! i=!i)'246 8 Ten lines
Common basic commands for Linux: Three musketeers command-awk ternary expression