1

如何在 GREP 中只打印两个文本文件的不同行?我只需要打印不在第二个文本文件中的行......

谢谢你。

4

2 回答 2

7

You can use -F -f <file>:

grep -Fvf file2 file1

This tells you the lines of file1 which do not (-v) appear in file2.

于 2013-09-01T14:30:42.907 回答
3

Why do you need to use grep?

Sounds like you need diff

$ cat file1
a
b
c

$ cat file2
b

You can use diff to compare them:

$ diff file1 file2
1d0
< a
3d1
< c

Use -y option to generate better visaul comparison:

$ diff -y file1 file2
a                                                             <
b                                                             b
c                                                             <
于 2013-09-01T14:31:39.650 回答