remove duplicate lines found in another file

Posted on 2012-08-17
Last Modified: 2012-08-17
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.

Question by:gloriaewold41
    LVL 34

    Accepted Solution

    $test = true;
    $afile = file("a.file");
    $bfile = file("b.file");
    $diff = array_diff($afile,$bfile);

    LVL 34

    Assisted Solution

    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.

    Author Closing Comment

    Works great. Thanks.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now