how to delete same lines in file .txt but keep one

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adnanrabbi
Forum Newbie
Posts: 4
Joined: Fri Apr 22, 2011 9:49 am

how to delete same lines in file .txt but keep one

Post by adnanrabbi »

how to delete same lines in file .txt but keep one (using php code) pls help
.text contain

=LDR 00000nam
=300 same text
=541 same text
=952 p000298

=LDR 00000nam
=300 same text
=541 same text
=952 p000299

=LDR 00000nam
=050 same text1
=082 same text1
=952 p002930

=LDR 00000nam
=050 same text1
=082 same text1
=952 p002931



out put
=LDR 00000nam
=300 same text
=541 same text
=952 p000298
=952 p000299

=LDR 00000nam
=050 same text1
=082 same text1
=952 p002930
=952 p002931
ayazhaider
Forum Newbie
Posts: 5
Joined: Fri Apr 22, 2011 11:18 am

Re: how to delete same lines in file .txt but keep one

Post by ayazhaider »

Try Following if you want to delete duplicate lines from your text file

// Write your filename
$filename = 'ur_file.txt';

$text = array_unique(file($filename));

$f = @fopen($filename,'w+');
if ($f) {
fputs($f, join('',$text));
fclose($f);
}

@yAz
adnanrabbi
Forum Newbie
Posts: 4
Joined: Fri Apr 22, 2011 9:49 am

Re: how to delete same lines in file .txt but keep one

Post by adnanrabbi »

thanks for quick reply
is it possible to search ignore following text if '=LDR 00000nam' text found just ignore no need to unique


as like this

=LDR 00000nam
=300 same text
=541 same text
=952 p000298
=952 p000299

=LDR 00000nam
=050 same text1
=082 same text1
=952 p002930
=952 p002931
adnanrabbi
Forum Newbie
Posts: 4
Joined: Fri Apr 22, 2011 9:49 am

Re: how to delete same lines in file .txt but keep one

Post by adnanrabbi »

Possible to add every sequence of =952%. add last sequence =LDR 00000nam
out put

=300 same text
=541 same text
=952 p000298
=952 p000299
=LDR 00000nam
=050 same text1
=082 same text1
=952 p002930
=952 p002931
=952 p002932
=LDR 00000nam
Post Reply