Score:0

Colorize diff side-by-side output and put label header on diff

cn flag

I am writing a bash script to compare 2 folders.

The script will collect some user information (folders and files to compare) and afterwards loop through an array to show differences.

Something like:

caseNames = ("Path1" "Path2")

elementsToCompare= ("FolderA" "FolderB" "fileA" "fileB")


for i in ${elementsToCompare[@]}; do
    diff -r "${caseNames[0]}""/"$i "${caseNames[1]}""/"$i| colordiff | less -R

done

Now, I would like to show a side-by-side comparison between the files. The switch -y exists in diff to make this but it will not colorize the output. Is there any way to do this?

Additionally, the side-by-side comparison shows the full document, is it possible do restrict this to n lines above and bellow the difference?

Finally, I would like to tell the user what file is being examined. Sometimes diff puts a header like :

diff -r  Path1/FolderA/foo Path2/olderA/foo

Other times it will just show the file differences (I have experienced this with plain text files) without me knowing which file is being compared. Is it possible to put a header to show the user the files under comparison?

Best Regards!

sudodus avatar
jp flag
If you use `diff -u file1 file2 > filediff.patch` and view it in the text editor `geany`, there will be nice colors to help see what i think you want to see. try `geany filediff.patch`. The file `filediff.patch` can also be used to patch `file2` to get the same content as `file2`. See `man diff` and `man patch` to get more details. You can get colours in the editor `nano` too, try also the command line : `nano filediff.patch`, and use the tool you like best.
N0rbert avatar
zw flag
Meld or FreeFileSync will do this in graphical way. Do no invent bicycle with square wheels.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.