How can I do one way in Linux?

How to make one-way diff in Linux?

Normal diff behavior:

Usually diff will tell you all the differences between the two files. For example, he will tell you everything that is in file A, which is not in file B, and also tells you everything that is in file B, but not in file A. For example:

File A contains:

cat
good dog
one
two

File B contains:

cat
some garbage
one
a whole bunch of garbage
something I don't want to know

If I do a regular diff as follows:

diff AB

the output would be something like this:

2c2
< good dog
---
> some garbage
4c4,5
< two
---
> a whole bunch of garbage
> something I don't want to know

What I'm looking for:

What I want is only the first part, for example, I want to know everything that is in file A, but not file B. However, I want it to ignore everything that is in file B, but not in file A.

I want a team or series of commands:

???? Ab

which outputs the result:

2c2
< good dog
4c4,5
< two

, diff sed awk, , . , --- > .

: .

. "": , , RedHat Linux

. , , (, ): diff

+3
3

diff A B|grep '^<'|awk '{print $2}'

grep '^<' , <

awk '{print $2}'

+3

, , (, , ):

comm -23 <(sort A) <(sort B)

comm , , -2 " , ", -3 " , ".

"", , , diff/awk ( grep ), diff A B | awk '/^</ { $1 = ""; print }'.

EDIT: , - ...

+2

As stated in the comments, basically the correct answer:

diff A B | grep '^<'

although it will give a way out

< good dog
< two

but not

2c2
< good dog
4c4,5
< two
+2
source

Source: https://habr.com/ru/post/1606456/


All Articles