I have a text file contains ldap data in the give below format, our default structure says every user must have its own respective home directory but in given below i found many users have the same home directory and that is homeDirectory: /home/UGstudent/2013 so i want to change it to homeDirectory: /home/UGstudent/2013/xyz means i need to take the same name as in uid: abc field of each user and append it to homeDirectory:  field.dn: uid=abc,ou=People,dc=abc,dc=com  uid: abc   cn: abc defobjectClass: account  objectClass: posixAccount  objectClass: top  objectClass: shadowAccount  shadowLastChange: 15923  shadowMax: 99999  shadowWarning: 7  loginShell: /bin/bash  uidNumber: 10000  gidNumber: 9000  homeDirectory: /home/myworker/2013/abc  gecos:: QWpheSBLasdfkshdfksdkfhUJTTVMxMywJU1RVLA==  structuralObjectClass: account  entryUUID: 74dec3aa-0fb6-4d86sfs-962e-432ea83c75e0  creatorsName: cn=Manager,dc=abc,dc=com  createTimestamp: 20160806091411Z  userPassword:: e1NIQXKSJFkHkjhfskDAvS2NwYWxXcm4zY2JEL2wxYVk9  entryCSN: 20160121043505.309136Z#000000#000#000000  modifiersName: uid=abc,ou=People,dc=abc,dc=com  modifyTimestamp: 20160121043505Z  dn: uid=xyz,ou=People,dc=abc,dc=com  uid: xyz  cn: xyz jakas  objectClass: account  objectClass: posixAccount  objectClass: top  objectClass: shadowAccount  shadowLastChange: 15923  shadowMax: 99999  shadowWarning: 7  loginShell: /bin/bash  uidNumber: 1260  gidNumber: 9000  homeDirectory: /home/myworker/2013  gecos:: QWtzaGFqIFByZfdsfdsfdsgDAzLAlCU01TMTMsCVNUVSw=  structuralObjectClass: account  entryUUID: 81fc5c44-6d63-4d4a-bb74-7ae5f12bbeef  creatorsName: cn=Manager,dc=abc,dc=com  createTimestamp: 20160806091411Z  userPassword:: e1NIQXkjfshgjdsJMQTB2SsdfSGFMekpZSkV1ZkZsWlE9  entryCSN: 20150118182228.898901Z#000000#000#000000  modifiersName: uid=xyz,ou=People,dc=abc,dc=com  modifyTimestamp: 20160118182228Z  
modify file using awk or sed
sed;awk;vim;ldap
A generic awk alternative:awk '    /^uid:/ {        uid=$2    }    /^homeDirectory:/ {        if ($NF !~ uid$) { $NF = $NF/uid }    }    { print }    ' text.file