Write a new file from 2 files as input to the script

Hi-
I am hoping someone can give me some pointers to get me started. I have a file which contains some dn's .e.g file 1
cn=bob,cn=user,dc=com
cn=kev,cn=user,dc=com
cn=john,cn=user,dc=com

I have a second file e.g. file.template which looks something like :-

dn: <dn>
objectclass: inetOrgPerson
objectclass: ePerson
objectclass: organizationalPerson
objectclass: person
objectclass: top
cn: <name>
sn: <name>
userpassword: password
uid: <name>

I want to read each line from file 1 and then by using file.template, generate a third file. I don't have to do it this way though - I basically have a file containing a list of dn's and I need to generate an ldif file. Anyone got any ideas please?
Thanks

can you post how the resulting file should look like??

It should look like :-

dn: cn=bob,cn=user,dc=com
objectclass: inetOrgPerson
objectclass: ePerson
objectclass: organizationalPerson
objectclass: person
objectclass: top
cn: bob
sn: bob
userpassword: password
uid: bob

dn: cn=john,cn=user,dc=com
objectclass: inetOrgPerson
objectclass: ePerson
objectclass: organizationalPerson
objectclass: person
objectclass: top
cn: john
sn: john
userpassword: password
uid: john

etc

I have been thinking that this may not be such a good way of doing this. I think maybe it would be better to have one input file containing the dn's and then just write a new file from the script.

What is the best way to read in a file, process it line by line and write out a new file please (bear in my mind I don't know shell scripting very well) ?

e.g.
while read line
do

print "$line" >> $outfile

print "objectclass: inetOrgPerson" >> $outfile

print " objectclass: ePerson" >> $outfile
print "objectclass: organizationalPerson" >> $outfile
print "objectclass: person" >> $outfile
print "objectclass: top" >> $outfile
print "cn: john" >> $outfile
print "sn: john" >> $outfile
print "userpassword: password" >> $outfile
print "uid: john" >> $outfile
done < $filename

I am sure the above syntax is wrong .. can someone tell me the best way to do something like that ?

Going one step further, if my input file contained the dn and additional info, e.g. :-

# dn, firstname, surname, password
cn=bob,cn=user,dc=com, bob, jones, Password123
cn=john,cn=user,dc=com, john, smith, Password456

how could I read each line into the script but put dn, firstname, surname and password into separate variables and ignore comments ??

Many thanks

how about doing something like this...

awk '{FS="[,=]"}
{print "dn: " $0
print "objectclass: inetOrgPerson"
print "objectclass: ePerson"
print "objectclass: organizationalPerson"
print "objectclass: person"
print "objectclass: top"
print "cn: "$2
print "sn: "$2
print "userpassword: password"
print "uid: "$2
}' infile

infile should contain

cn=bob,cn=user,dc=com
cn=kev,cn=user,dc=com
cn=john,cn=user,dc=com

from here you can do the addition stuff too.

snipper ,

It would be highly appreciative if u post what is exact input your giving and the output your expecting instead of the explaining the same.

Thanks ,

panyam

Hi -
This is the input file :-
# dn, firstname, surname, password
cn=bob,cn=user,dc=com, bob, jones, Password123
cn=john,cn=user,dc=com, john, smith, Password456

and the output file should look like:-

dn: cn=bob,cn=user,dc=com
objectclass: inetOrgPerson
objectclass: ePerson
objectclass: organizationalPerson
objectclass: person
objectclass: top
cn: bob
sn: bob
userpassword: password
uid: bob

dn: cn=john,cn=user,dc=com
objectclass: inetOrgPerson
objectclass: ePerson
objectclass: organizationalPerson
objectclass: person
objectclass: top
cn: john
sn: john
userpassword: password
uid: john

Thanks for the suggestions.