Jump to content

AWK - find variable value in array


drumhrd

Recommended Posts

 

:wtf:

:confused:

:'(

I am attempting to find the value of a variable in a created array.

 

as you can see from the script below. I am identifying any "non system" users by looking at the passwd file and what I want to do is take the userID from passwd, compare it to my known list of system users. I do not want a print out of system users, I just want users that have been created after the fact.

 

The problem is, the if statement is not working and I am getting a print out of all my users, including the ones I do not want to see

 

awk 'BEGIN {
FS=":";
a[1] = "adm";
a[2] = "apache";
a[3] = "bin";
a[4] = "daemon";
a[5] = "ftp";
a[6] = "games";
a[7] = "gopher";
a[8] = "halt";
a[9] = "lp";
a[10] = "mail";
a[11] = "mysql";
a[12] = "named";
a[13] = "news";
a[14] = "nobody";
a[15] = "ntp";
a[16] = "operator";
a[17] = "pcap";
a[18] = "postfix";
a[19] = "radvd";
a[20] = "root";
a[21] = "rpc";
a[22] = "rpm";
a[23] = "shutdown";
a[24] = "sshd";
a[25] = "sync";
a[26] = "syscheck";
a[27] = "testuser";
a[28] = "tomcat4";
a[29] = "uucp";
a[30] = "vcsa";

while ( getline < "/etc/passwd" ) { 
  if ($1 in a){}
  else {print $1}
}
}' 

Link to comment
https://forums.phpfreaks.com/topic/226700-awk-find-variable-value-in-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.