Update LDIF User info based on Test User Certs ID's

Hi I need help..........

I have an Sun One Directory server LDIF file with 5000 user entries, I need to change the data to match Test ID's, so I can run a perf test.

I'm way out of my league as I have not done any scripting for 10 years.

There are four entries for each user in the file that I need to update with the uid from a list in another file.

dn: uid=xxxzzze000,l=emea,ou=internal,ou=people,dc=company,dc=com
mail: xxxzzze000.xxxzzze000@uk.company.com
uid: xxxzzze000

The real users are not wholly sequential........

They range from

xxxzzze000 - xxxzzze999
xxxzzzf000 - xxxzzzf999
xxxzzzh000 - xxxzzzh999
xxxzzzi000 - xxxzzzi999
xxxzzzj000 - xxxzzzj999

The Test users are

xxxzzze1000 -xxxzzze5000

Has anyone got a script for changing entries in a file based on input from another file?

Thx

---------- Post updated at 05:13 PM ---------- Previous update was at 02:09 PM ----------

I think I nead something like this.....

#!/bin/bash
read oldval
read newval
while read line
do
{
sed 's/'$oldval'/'$newval'/g' $line >$line".new"
}
done<list.txt

If I am correct this would take a list input from a file; read the old value and replace with the new value in the same file

so if the file had in it -

xxxzzze000 xxxzzze1000
xxxzzze001 xxxzzze1001
xxxzzze002 xxxzzze1002

The script should replace

dn: uid=xxxzzze000,l=emea,ou=internal,ou=people,dc=company,dc=com
mail: xxxzzze000.xxxzzze000@uk.company.com
uid: xxxzzze000

dn: uid=xxxzzze001,l=emea,ou=internal,ou=people,dc=company,dc=com
mail: xxxzzze001.xxxzzze001@uk.company.com
uid: xxxzzze001

dn: uid=xxxzzze002,l=emea,ou=internal,ou=people,dc=company,dc=com
mail: xxxzzze002.xxxzzze002@uk.company.com
uid: xxxzzze002

with the following

dn: uid=xxxzzze1000,l=emea,ou=internal,ou=people,dc=company,dc=com
mail: xxxzzze1000.xxxzzze1000@uk.company.com
uid: xxxzzze1000

dn: uid=xxxzzze1001,l=emea,ou=internal,ou=people,dc=company,dc=com
mail: xxxzzze1001.xxxzzze1001@uk.company.com
uid: xxxzzze1001

dn: uid=xxxzzze1002,l=emea,ou=internal,ou=people,dc=company,dc=com
mail: xxxzzze1002.xxxzzze1002@uk.company.com
uid: xxxzzze1002

Can anyone verfiy?

The file is in Standard LDIF format so there are a block of entries per user

dn: uid=xxxzzze000,l=emea,ou=internal,ou=people,dc=company,dc=com
objectClass: inetorgperson
objectClass: person
objectClass: internalperson
objectClass: organizationalperson
objectClass: person
objectClass: top
objectClass: service
c: GB
cn: Alasdair J 
employeeNumber: 000300
givenName: Alasdair
mail: xxxzzze000.xxxzzze000@uk.company.com
preferredLanguage: en
countryCode: UK
employeeType: Test
jobTitle: INTNST
los: ABAS
sn: J
uid: xxxzzze000
userPassword:: 

The second file is just a list of id's in sequential order. So I need to finds the id in the LDIF and change it based on the new ID's in all the correct places in the LDIF for 5000 users.

how is the input file formatted? You're on the right track.. but i think your read oldval/newval statements aren't going to do much.

Are the two files formatted kind of similarly? or no?

Hi, I suspect this should be enough to make the desired changes if you just want to change the three digits to four, the first being a 1:

sed 's/xxxzzz./&1/g infile > infile.new

Thanks your right its basically 1 sed command...........

:slight_smile: