i have two different txt files. The first one is the source file. The second file file b is the same file, but after some edits. New lines have been added, and some lines from file A have been deleted . Our task is to get in two new separate files the lines that have been added to file a, and in a new file the lines that have been removed from file a
a.txt
Common
Common
A-ONLY
Common
b.txt
Common
B-ONLY
Common
Common
I need as output in a separate new file to show lines removed from a.txt
output:
A-ONLY
I then need as in a separate new file output to show lines added to a.txt
output:
B-ONLY
How can i do it with ubuntu linux commands with sed or awk? do i first need to sort the files i compare?
2
Answers
Assuming the files can be sorted before comparison:
With GNU diff:
With standard diff and awk:
It is probably possible to implement with
awk
alone but you would just be trying to re-inventdiff
.With standard diff and sed:
It’s probably very difficult to implement with
sed
alone, if it is even possible.