Question

I have 2 files : One.lst and Two.lst.

One.lst contains :

a
b
c
d
e

Two.lst contains :

c
d

I need One.lst to contain only a,b,e ie removing the lines from One.lst that are already present in Two.lst.

So,the updated One.lst will be :

a
b
e
Was it helpful?

Solution

This is a job for grep:

$ grep -vf Two.lst One.lst
a
b
e

To update the file with the content, do:

grep -vf Two.lst One.lst > temp_file && mv temp_file One.lst

From man grep:

-f FILE, --file=FILE

Obtain patterns from FILE, one per line.

-v, --invert-match

Invert the sense of matching, to select non-matching lines.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top