Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Filtering lines from one file from another

by bellaire (Hermit)
on Feb 03, 2011 at 03:31 UTC ( #885885=note: print w/replies, xml ) Need Help??

in reply to Filtering lines from one file from another

If you supply some code, you can get some Perl-specific help. Until then, as an aside, you can do this without perl at all if you're on a system with grep installed:
$ grep -vf file2 file1 cat dogwhisperer mother

Replies are listed 'Best First'.
Re^2: Filtering lines from one file from another
by Limbic~Region (Chancellor) on Feb 03, 2011 at 16:26 UTC
    First, I believe your grep usage would need to be modified because as-is, the lines will be treated as regular expressions and not fixed strings. Second, I wonder how this would work if arbitrarily large files need to be supported. For instance, sort resolves this issue by using an on-disk divided and conquer strategy so assuming you have enough free filesystem, you can sort any size file. I just don't know how grep would do in this situation.

    Cheers - L~R

      I have tried with grep -xvf file2 file1 and seems to work
        True, or even further, grep -xvFf, to not only match the entire line, but to treat the "patterns" from file2 as fixed strings rather than regexes. L~R has a good point about large file size limitations, though. I can't really speak to that point.
        The reason it seems to work is due to your specific data set. The solution without modification is fragile. This is because grep assumes that the file contains regular expressions (called patterns) not fixed strings. It would be better to add the -F option as shown by bellaire to treat them as fixed strings.

        Cheers - L~R

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://885885]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2019-10-23 15:44 GMT
Find Nodes?
    Voting Booth?