19 C
Jaipur
Friday, October 30, 2020

How to Diff Command Colorize Output on Linux

Must read

How To Use pulseaudio-dlna To Stream Audio From Ubuntu 20.10 To Chromecast Devices

pulseaudio-dlna is a streaming server which allows streaming audio from your Linux computer to a Chromecast or DLNA / UPNP device in the same...

Nokia cuts full-year profit forecast, announces new strategy – Latest News

STOCKHOLM/HELSINKI: Nokia cut its full-year profit forecast even as the telecom network equipment maker's quarterly underlying profit met expectations in its first earnings under...

payments technology: JPMorgan backs UK payments technology company Icon Solutions – Latest News

JPMorgan Chase & Co has made a strategic investment in Icon Solutions, a UK-based company that advises and provides technology to banks to help...

tcl 4k tv: TCL expands its smart TV lineup with TVP615 Android TV, price starts at Rs 23,999

Expanding its smart TV lineup, consumer electronics brand TCL has launched its latest 4K UHD TV -- TVP615 in India. The TV runs

Diff is a command-line utility that helps users to visually compare differences between 2 files line by line on a Linux/Unix system. Colordiff utility is a Perl script that is an improved version of diff. It colorizes the output so that the differences between the files are clearly visible on the terminal.

In a nutshell, the diff command tool can be used to perform the following

1. View changes that exist between 2 versions of a file.

2. Draw comparisons between 2 program files

In this tutorial, you will learn how to colorize diff output on Linux using the help of colordiff commands.

How to install Colordiff  utility

Before we get to the ins and outs of using d colordiff, let’s first install it.

Install Colordiff on Ubuntu/Debian/Mint

To install the colordiff utility on Debian-based systems such as Ubuntu and Mint, open your terminal and run the command:

$ sudo apt install colordiff

Install Colordiff on RHEL/CentOS

To install colordiff on rpm distributions such as Hat and CentOS, run:

$ sudo yum install colordiff

Install Colordiff on Arch Linux

For Arch Linux and derivatives of Arch Linux such as Manjaro, run:

$ sudo pacman -S colordiff

Install Colordiff on FreeBSD and OpenBSD

To install  Colordiff  on FreeBSD, run the command:

$ sudo pkg install  colordiff

For OpenBSD execute:

$ pkg_add -v colordiff

How to diff colorize

The syntax for using the colordiff and diff commands is quite simple and straightforward.

Use the syntax

$  color diff file1 file2

For example,  I have created 2 files as shown

create two files to compare using colordiff

To check the differences that exist between the two files, run the command:

$  colordiff file1.txt file2.txt

compare two files using colordiff command

Additionally, you can use the diff command and pipe the output to colordiff as shown:

or

$ diff -u file1.txt  file2.txt | colordiff

diff command colorized

Alternatives to diff color

Another handy way you can use to compare files is by use of the grc command as shown:

$ grc diff file1.txt file2.txt

Combine grc with diff

Another cool tool I found is Icdiff which is an improved colored diff.

You can install Icdiff using pip command, run:

$ pip install git+https://github.com/jeffkaufman/icdiff.git

Conclusion

In this tutorial, you learned how to colorize diff output with help of colordiff command-line utilities to compare files on the terminal in a colorized format. If the two files are identical, then no output is printed on the screen. To get more information about how those two utilities are used, simply visit the man diff and man colordiff.

Give us a shout and let us know how your experience went. Thank you.

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How To Use pulseaudio-dlna To Stream Audio From Ubuntu 20.10 To Chromecast Devices

pulseaudio-dlna is a streaming server which allows streaming audio from your Linux computer to a Chromecast or DLNA / UPNP device in the same...

Nokia cuts full-year profit forecast, announces new strategy – Latest News

STOCKHOLM/HELSINKI: Nokia cut its full-year profit forecast even as the telecom network equipment maker's quarterly underlying profit met expectations in its first earnings under...

payments technology: JPMorgan backs UK payments technology company Icon Solutions – Latest News

JPMorgan Chase & Co has made a strategic investment in Icon Solutions, a UK-based company that advises and provides technology to banks to help...

tcl 4k tv: TCL expands its smart TV lineup with TVP615 Android TV, price starts at Rs 23,999

Expanding its smart TV lineup, consumer electronics brand TCL has launched its latest 4K UHD TV -- TVP615 in India. The TV runs

paytm: Parliamentary panel questions Paytm about Chinese investment, storing of data in servers abroad – Latest News

A parliamentary panel on Thursday questioned Paytm representatives about the quantum of Chinese investment in the company and told them that the servers on...