Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

diff files comparing only first n characters of each line

I have got 2 files. Let us call them md5s1.txt and md5s2.txt. Both contain the output of a

find -type f -print0 | xargs -0 md5sum | sort > md5s.txt

command in different directories. Many files were renamed, but the content stayed the same. Hence, they should have the same md5sum. I want to generate a diff like

diff md5s1.txt md5s2.txt

but it should compare only the first 32 characters of each line, i.e. only the md5sum, not the filename. Lines with equal md5sum should be considered equal. The output should be in normal diff format.

like image 494
Speckinius Flecksis Avatar asked May 18 '11 15:05

Speckinius Flecksis


People also ask

What is diff in command-line?

diff is a command-line utility that allows you to compare two files line by line. It can also compare the contents of directories. The diff command is most commonly used to create a patch containing the differences between one or more files that can be applied using the patch command.

What does diff return if the files are the same?

Comparing files with the diff command In this example, the extra lines are in backup. html. If diff shows no output, that means the two files are the same.

What is diff in shell script?

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.


1 Answers

Easy starter:

diff <(cut -d' ' -f1 md5s1.txt)  <(cut -d' ' -f1 md5s2.txt)

Also, consider just

diff -EwburqN folder1/ folder2/
like image 61
sehe Avatar answered Sep 18 '22 02:09

sehe