• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

remove duplicate lines found in another file

Hi experts,

I need to remove from a.txt every line found in b.txt (case sensitive)
The files contain one word on each line.

Thanks.
0
gloriaewold41
Asked:
gloriaewold41
  • 2
2 Solutions
 
gr8gonzoConsultantCommented:
<?php
$test = true;
$afile = file("a.file");
$bfile = file("b.file");
$diff = array_diff($afile,$bfile);

if($test)
{
  print_r($diff);
}
else
{
  file_put_contents("a.file",$diff);
}
?>
0
 
gr8gonzoConsultantCommented:
That should work for most general needs. If a and b are huge files, then you might run into memory issues, and may need to either increase the memory limit or use a more complex and slower way to do this.

Set $test to false when you have reviewed the results and are satisfied that it meets your needs. It should overwrite "a.file" with the results.
0
 
gloriaewold41Author Commented:
Works great. Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now