I would like to write a bash script or a few shell commands that solves my problem. I have two files, old.txt, new.txt. I would like to produce a file, diff.txt, that has only the lines that have changed or are new. For instance if I had:
old.txt:
Sierra
Tango
Oscar
Victor
Whiskey
Yankee
new.txt:
Sierra
Tango
Echo
Osc__ar
Victor
Uniform
Whiskey
Yan__kee
I would want a diff.txt that looks like this:
Echo
Osc__ar
Uniform
Yan__kee
For perspective, I am writing this script to help me create a differential Motorolla S2 record for loading programs over serial port to an embedded computer. I know bash fairly well, I just don't know where to get started.
diff stands for difference. This command is used to display the differences in the files by comparing the files line by line. Unlike its fellow members, cmp and comm, it tells us which lines in one file have is to be changed to make the two files identical.
To compare files in Linux and even in macOS, a utility used is called the “diff”. The “diff” utility compares two files and gives information about the differences between the two files. The developers primarily use the “diff” command to create patch files.
$ grep -v -f old.txt new.txt
Echo
Osc__ar
Uniform
Yan__kee
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With