awk or sed to split dn

Hello -

I have an input file with user dn's. e.g.

cn=peter,cn=users,dc=com,dc=uk
cn=simon,cn=users,dc=com,dc=uk
cn=john,cn=users,dc=com,dc=uk
cn=fred,cn=users,dc=com,dc=uk

My script needs to generate an LDIF file based on this input file as below:-

awk '{ FS="[=|,]"}
   {
      print "dn: " $1
      print "changetype: add"
      print "objectclass: top"
      print "changetype: person"
      print "uid: " $1
      print "mail: " $1"@com.uk"
      print "cn: " $1
      print "userpassword: " $password
}' $INFILE >> $OUTFILE 

Now I can't work out what the awk statement should look like so that "dn" is assigned the full dn from the file and uid and cn are assigned just a segment. For example, the output for one line should look like:

dn: cn=peter,cn=users,dc=com,dc=uk
 changetype: add
objectclass: top
changetype: person
uid: peter
mail: peter@com.uk
cn: peter
userpassword: somepass

Clearly the above will not work. Any help much appreciated.
Many thanks

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

++++++++++++++++++++++++++++++++++++++++++++++++++

Try this:

awk -F, '
{
split($1,a,"=")
print "dn: " $0
print "changetype: add"
print "objectclass: top"
print "changetype: person"
print "uid: " a[2]
print "mail: " a[2]"@com.uk"
print "cn: " a[2]
print "userpassword: " "somepass"
}' $INFILE >> $OUTFILE