my_attr1:1 PxED1 #### #!/usr/bin/perl while (defined($file = readdir BIN)) { if (($file=~m/test.txt/)){ open FILE,$file; my @lines=; for $line (@lines){ if ($line=~/cn=/) { print "\n"; print "$line"; print "changetype: modify"."\n"; print "delete: my_attr1"."\n"; } elsif (($line=~/^my_attr1/)&& ($line=~/1<\/order>/)){ print "$line"; } } } } close(FILE); closedir(BIN); #### cn=abc,ou=People,dc=example,dc=com my_attr1:0PxED1 my_attr1:1 PxED1 my_attr1:2PxED1 my_attr1:3/order>PxED1 uid:abc cn:abc mail:abc1@hotmail.com my_attr2:M1 20060301162200.623Z sn:def givenname:abc cn=def,ou=People,dc=example,dc=com my_attr1:1 PMxED1 uid:def cn:def mail:def@msn.com my_attr2:M1 20060301162200.623Z sn:jkl givenname:jkl cn=jkl,ou=People,dc=example,dc=com my_attr1:2P1xED1 my_attr1:1 P1xED1 uid:jkl cn:jkl mail:jkl2@hotmail.com my_attr2:M1 20060301162200.623Z sn:jkl givenname:jkl cn=mnp,ou=People,dc=example,dc=com my_attr1:1PM23xED1 uid:mnp cn:mnp mail:mnp@msn.com my_attr2:M123 20060301162200.623Z sn:mnp givenname:mnp #### $ ./mymakeldif.txt cn=abc,ou=People,dc=example,dc=com changetype: modify delete: my_attr1 my_attr1:1 cn=def,ou=People,dc=example,dc=com changetype: modify delete: my_attr1 my_attr1:1 cn=jkl,ou=People,dc=example,dc=com changetype: modify delete: my_attr1 my_attr1:1 cn=mnp,ou=People,dc=example,dc=com changetype: modify delete: my_attr1 my_attr1:1PM23xED1