Page 1 of 1

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

Posted: Fri Apr 22, 2011 10:07 am
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

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

Posted: Fri Apr 22, 2011 11:32 am
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

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

Posted: Sat Apr 23, 2011 12:23 am
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

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

Posted: Sat Apr 23, 2011 4:17 am
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