Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Firstly, which is the best and fastest unix command to get only the differences between two files ? I tried using diff to do it (below).

I tried the answer given by Neilvert Noval over here - Compare two files line by line and generate the difference in another file

code -

diff -a --suppress-common-lines -y file1.txt file2.txt >> file3.txt

But, I get a lot of spaces and a > symbol also before the different lines. How do I fix that ? I was thinking of removing trailing spaces and the first '>', but not sure if that is a neat fix.

My file1.txt has -

Hello World!
Its such a nice day!
#this is a newline and not a line of text# 

My file1.txt has -

Hello World!
Its such a nice day!
Glad to be here!
#this is a newline and not a line of text# 

Output - " #Many spaces here# > Glad to be here:)"

Expected output - Glad to be here:)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

Another way to get diff is by using awk:

awk 'FNR==NR{a[$0];next}!($0 in a)' file1 file2

Though I must admit that I haven't run any benchmarks and can't say which is the fastest solution.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...