Need help to modify the files

HI i have file call
groups.ldif and it has bellow lines

dn: cn=tps-uk,ou=groups,l=UK,dc=domain,dc=lan
uniqueMember: uid=salam,ou=users,l=UK,dc=domain,dc=lan
dn: cn=dev-admin,ou=groups,l=UK,dc=domain,dc=lan
memberUid: uid=salam,ou=users,l=UK,dc=domain,dc=lan

Basically i want to insert 2 lines in between dn and uniquemember or dn
and memberUID
which is :

changetype: modify
delete: uniqueMember

changetype: modify
delete: uniqueMember

Now the logic is :

if it see like this

dn: cn=tps-uk,ou=groups,l=UK,dc=domain,dc=lan
uniqueMember: uid=salam,ou=users,l=UK,dc=domain,dc=lan

then some how i need to insert those 2 lines so it will be :

dn: cn=tps-uk,ou=groups,l=UK,dc=domain,dc=lan
changetype: modify
delete: uniqueMember
uniqueMember: uid=salam,ou=users,l=UK,dc=domain,dc=lan

but if he see like this

dn: cn=dev-admin,ou=groups,l=UK,dc=domain,dc=lan
memberUid: uid=salam,ou=users,l=UK,dc=domain,dc=lan

it has to be like this
dn: cn=dev-admin,ou=groups,l=UK,dc=domain,dc=lan
changetype: modify
delete: uniqueMember
memberUid: uid=salam,ou=users,l=UK,dc=domain,dc=lan

so the end result will be

dn: cn=tps-uk,ou=groups,l=UK,dc=domain,dc=lan
changetype: modify
delete: uniqueMember
uniqueMember: uid=salam,ou=users,l=UK,dc=domain,dc=lan
dn: cn=dev-admin,ou=groups,l=UK,dc=domain,dc=lan
changetype: modify
delete: uniqueMember
memberUid: uid=salam,ou=users,l=UK,dc=domain,dc=lan

I would really appreciate any thoughts on this

Something line this perhaps? Not knowing the format of your data
beyond the two examples you have given

DATA.each do |line|
if line =~ /^uniqueMember:/ or line =~ /^memberUid:/
puts “changetype: modify”
puts “delete: uniqueMember”
end
puts line
end

END
dn: cn=tps-uk,ou=groups,l=UK,dc=domain,dc=lan
uniqueMember: uid=salam,ou=users,l=UK,dc=domain,dc=lan
dn: cn=dev-admin,ou=groups,l=UK,dc=domain,dc=lan
memberUid: uid=salam,ou=users,l=UK,dc=domain,dc=lan

Hi
i have done that
but the problem is
that way it will produce this

dn: cn=tps-uk,ou=groups,l=UK,dc=domain,dc=lan
uniqueMember: uid=salam,ou=users,l=UK,dc=domain,dc=lan
dn: cn=dev-admin,ou=groups,l=UK,dc=domain,dc=lan
memberUid: uid=salam,ou=users,l=UK,dc=domain,dc=lan

but this line
uniqueMember: uid=salam,ou=users,l=UK,dc=domain,dc=lan
has to go at last
lke this

dn: cn=tps-uk,ou=groups,l=UK,dc=domain,dc=lan
changetype: modify
delete: uniqueMember
uniqueMember: uid=salam,ou=users,l=UK,dc=domain,dc=lan

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs