How to remove identical lines in one file from another, using sed

sedtext processing

I have two files, one being a superset of the other. I want to remove the identical lines in the smaller files from the larger file.

One possible complication is that the lines contain backslashes.

How do I do this?

Best Answer

Here is my snippet:

remove_lines()
{
    # remove lines from a file 
    #  
    # $1 - source file with patterns of lines to be removed
    # $2 - destination file
    tmpfile=$(mktemp "$(dirname -- "$2")"/XXXXXXXX) &&
    grep -F -f "$1" -v -- "$2" >>"$tmpfile" &&
    mv -- "$tmpfile" "$2" &&
}

EDIT: I've just realized that there is no sed in it, but that wasn't critical, was it?

Related Question