Solved removing duplicate rows based on a column !!

October 27, 2011 at 11:30:57
Specs: Windows Vista
Hey Guys, I have a file like this


As you can see there are two records with My script should find out if the number of duplicate email addresses are more than 10 (10 records with the same email address) then remove it, otherwise preserve it.


See More: removing duplicate rows based on a column !!

Report •

October 27, 2011 at 13:14:15
✔ Best Answer
A method using awk: read the data file and save the count of the third field into an array. Then, read the same file in the main loop and print only lines where the 3rd field count is less than 10:


rm -f mynewdata.txt
awk ' BEGIN { FS="|";
   while ( getline < "mydata.txt" > 0 )
if($3 in myarr)
  if(myarr[$3] < 10)
     print $0 >> "mynewdata.txt"

} ' mydata.txt

Report •

October 28, 2011 at 08:06:56
Thanks and it worked like a charm. I need one more thing if you can help me out..



Similar like above, I need to check for First name + Last name duplicates in a file and print if they are < 10. Please let me know.

Report •
Related Solutions

Ask Question