root_count.sh
#!/bin/bash
awk -F: '{i=1;while(i<=NF){if($i~/root/){x++};i++}} END{print "The count of root is:" x}' /etc/passwd
验证:
[root@logstash ~]# sh root_count.sh
The count of root is:4
[root@logstash ~]#
root_count.sh
#!/bin/bash
awk -F: '{i=1;while(i<=NF){if($i~/root/){x++};i++}} END{print "The count of root is:" x}' /etc/passwd
验证:
[root@logstash ~]# sh root_count.sh
The count of root is:4
[root@logstash ~]#