I need to delete duplicate records in a file that is around 30MB. Below is what I need. Below are the entries of input file and the output file that I need. Each section of input file is separated by an empty line. Some of these sections have duplicate uid values. I want to retain only one UID per section. I do not want to make any changes to other entries though they are repeated. I tried some options but the values of d and e which are same in other sections are getting deleted. I have also attached a file with actual entries in it.
Thanks in advance
sam
Input file entries:
a: t1.com
uid: t1
b: t2
c: t3
uid: t1
d: t3
e: t4
a: u2.com
uid: u2
b: u2
c: t3
uid: u2
d: t3
e: t4
a: v2.com
b: v3
c: t3
uid: v3
d: t3
e: t4
Expected OutPut:
a: t1.com
uid: t1
b: t2
c: t3
d: t3
e: t4
a: u2.com
uid: u2
b: u2
c: t3
d: t3
e: t4
a: v2.com
uid: v3
b: v3
c: t3
d: t3
e: t4
The one liner nawk script worked. Thanks a lot for help...
SAM
---------- Post updated at 07:58 PM ---------- Previous update was at 07:57 PM ----------
Thank you all for the replies
---------- Post updated at 08:04 PM ---------- Previous update was at 07:58 PM ----------
I have one more question:
I am using the below script to add the uid value with cn value in a file. I have a file that is 28 mb. It is taking around 6 hours to precess the file. I am getting the expected result. Is there any other way we can expediate the same process with code changes.
while read LINE
do
if [[ $(echo $LINE|awk '{print $1}') != "cn:" ]]
then
echo $LINE >> out.txt
else
echo $LINE >> out.txt
echo $LINE | awk '{print "uid: "$2}' >> out.txt
fi
done < Test1.ldif