captain yossarian
captain yossarian

Reputation: 457

sed/awk - compare files, and return lines that have differences

I have two files

file1:

1
2
3
4
5
6

file2:

1
2a
3
4
5
6a

How can I script something that will return a third file that will output the lines that are different, along with the line number and filename? Ie. as lines 2 and 6 are different, the output is something like this, with a filename of 'file3':

file3

file1;line 2;2
file2;line 2;2a
file1;line 6;6
file2;line 6;6a

Thankyou as always!

Upvotes: 0

Views: 132

Answers (2)

Idriss Neumann
Idriss Neumann

Reputation: 3838

There are diff command as jkshah said. And there are too vimdiff tool.

If it's for occasional analysis and not to encapsulated in a script, vimdiff is very pleasant to use (using vim therefore allows access to vim commands such as search by regex, but also the syntax highlighting ...). In other words, with vimdiff you have a better visual diff.

vimdiff file1 file2

Upvotes: 0

jkshah
jkshah

Reputation: 11703

Probably you are looking for diff command

type man diff on your shell for more detials

Upvotes: 1

Related Questions