NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page Remove duplicate lines from data

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search
6 members in live chat ~  


Reply
 
LinkBack Thread Tools
Old 04-11-2011, 05:17 AM THREAD STARTER               #1 (permalink)
 
BillyConnite's Avatar
Join Date: Jul 2005
Location: Coffs H, Australia
Posts: 3,456
BillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond repute
 


Wildlife Parkinson's Disease Parkinson's Disease

Remove duplicate lines from data


Hi all,

Every so often i like to remove duplicate lines from a list of raw data, if you want to do this with php, here's a simple way to do so:
PHP Code:
<?php

/*
REMOVE DUPLICATE ENTRIES
DISPLAYS UNIQUE ENTIRES
*/

$list='random something
????: NamePros.com http://www.namepros.com/code/710519-remove-duplicate-lines-from-data.html
something or other
something
something else
something
randomness
chicken
bar snacks
something
foiled butter
O.o
...confuuussseeedd.........'
;

$listArray=explode("\n",$list);

$nonDupeList=array();

for(
$i=0;$i<count($listArray);$i++)
{
    if(!
in_array($listArray[$i],$nonDupeList))
    {
    
$nonDupeList[]=$listArray[$i];
    echo 
$listArray[$i]."<br />";
    }
}

?>
Hope you find it useful, i have countless times.

-Rhett.
BillyConnite is offline   Reply With Quote
Old 04-11-2011, 09:29 AM   #2 (permalink)
Tech Support
Join Date: Mar 2005
Posts: 4,944
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
A simpler way
????: NamePros.com http://www.namepros.com/showthread.php?t=710519

PHP Code:
<?php

$list 
'random something
something or other
something
something else
something
randomness
chicken
bar snacks
something
foiled butter
O.o
...confuuussseeedd.........'
;

$nonDupeList array_unique(explode("\n"$list));

echo 
implode('<br />'$nonDupeList);

?>
Eric is offline   Reply With Quote
Old 04-11-2011, 12:50 PM   #3 (permalink)
Domains my Dominion
 
sdsinc's Avatar
Join Date: Aug 2005
Location: Web 1.0
Posts: 9,955
sdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatness
 


Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV Animal Rescue Wildlife Breast Cancer Animal Rescue Wildlife
If you have a file and you want to remove the dupes, you could invoke the linux command line through the shell_exec function if allowed on your host:
Code:
sort <your file> | uniq
There are plenty of things that can be done more efficiently than in PHP
__________________
NameNewsletter.com - free lists of available domain names
ZoneFiles.net (beta) - ccTLD and gTLD droplists
sdsinc is offline   Reply With Quote
Old 04-11-2011, 09:21 PM THREAD STARTER               #4 (permalink)
 
BillyConnite's Avatar
Join Date: Jul 2005
Location: Coffs H, Australia
Posts: 3,456
BillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond repute
 


Wildlife Parkinson's Disease Parkinson's Disease
Thanks eric, i didn't realize there was an array_unique function, rep left .

Thanks sdsinc, i was specifically referring to php
Last edited by BillyConnite; 04-11-2011 at 09:26 PM.
BillyConnite is offline   Reply With Quote
Old 04-11-2011, 10:22 PM   #5 (permalink)
NamePros Regular
 
carob's Avatar
Join Date: Mar 2009
Posts: 540
carob is a name known to allcarob is a name known to allcarob is a name known to allcarob is a name known to allcarob is a name known to allcarob is a name known to all
 



Originally Posted by sdsinc View Post
If you have a file and you want to remove the dupes, you could invoke the linux command line through the shell_exec function if allowed on your host:
Code:
sort <your file> | uniq
There are plenty of things that can be done more efficiently than in PHP
Just wondering, are we talking about rewriting the file or just formatting for output (similar to select distinct in SQL)?
carob is offline   Reply With Quote
Old 07-05-2011, 12:01 AM   #6 (permalink)
First Time Poster!
Join Date: Jul 2011
Posts: 1
partiaran is an unknown quantity at this point
 



Sorry for the late reply. I use ddnr for duplicate text line removal. I have found it to be faster than php.
partiaran is offline   Reply With Quote
Old 03-02-2012, 12:18 AM   #7 (permalink)
New Member
Join Date: Feb 2012
Location: Research,Listening rock music
Posts: 2
structuresettlement is an unknown quantity at this point
 



Hi Billy Connite. I have tried this code but it didn't work.
structuresettlement is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Please - Need Script to Find & Remove Duplicate Links from a web page. senaia Programming 5 08-07-2006 01:55 PM
Dedicated Servers from just £45 $90 + [UK] 1 TB Data Transfer P4 3.0GHZ Only £119 blackicehosting Web Hosting Offers 0 07-12-2005 06:24 PM
Unmetered Summer Savings + 10% Discount blackicehosting Web Hosting Offers 0 07-02-2005 11:20 AM
New Site New Looks New Unmetered Savings blackicehosting Web Hosting Offers 0 05-29-2005 02:58 PM
#1 Bring Power to your Hosting :: UK Redbus + LA Dedicated Servers blackicehosting Web Hosting Offers 0 05-11-2005 10:57 AM

 
All times are GMT -7. The time now is 07:40 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger