简体   繁体   中英

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!

Probably you are looking for diff command

type man diff on your shell for more detials

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM