S
S
Stepan2014-01-15 15:06:32
*nix-like systems
Stepan, 2014-01-15 15:06:32

How to output only lines from file 2 that are not in file 1?

There are 2 txt files
1.txt

1
2
3
4
5

2.txt
1
3
12
44
55

How can I use diff or another utility to display only lines from file 2 that are not in file 1?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
YoungSkipper, 2014-01-15
@L3n1n

cat 2.txt | while read line ; do if ! grep -q $line 1.txt; then echo $line; fi ; done

For each line from 2.txt, we check if this line is not present in 1.txt, then we display it on the screen.

E
egor_nullptr, 2014-01-15
@egor_nullptr

diff 1.txt 2.txt | grep -E "^>" | sed -e "s/^> //g"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question