Issue
I have a file with a list of LDAP users with their password encoded. The file always has the same pattern as seen in the following example:
cn=user01,cn=users,dc=mycompany,dc=com,dc=ar
userpassword={SHA}sssFRwn116jjIF3EXEhecyFER=
cn=user02,cn=users,dc=mycompany,dc=com,dc=ar
userpassword={SHA}wwU3GCFOgidd5Z2h+jBKjsFER/w=
cn=user03,cn=users,dc=mycompany,dc=com,dc=ar
userpassword={SHA}GfGfptC2N43BDsfkqL6v0V+iFER=
cn=user04,cn=users,dc=mycompany,dc=com,dc=ar
cn=user05,cn=users,dc=mycompany,dc=com,dc=ar
userpassword={SHA}ZzZGptC2N43BFERkqL6v0V+ixUM=
I need some way to identify which is the user doesn't have a password (in this example the user 'cn=user04') , or at least get the line number in the file where the password is missing using linux console and/or bash scripting
Solution
It seems like if you have awk read the file in paragraph mode you can determine whether a record is missing the userpassword
attribute by testing if it contains a line break.
$ awk -F, -vRS= '!/\n/{print $1}' file
cn=user04
Answered By - oguz ismail