Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore asterix(*) while doing diff in Linux

Tags:

linux

diff

I am trying to use the standard diff command in Linux inorder to find differences in 2 files.The contents of the file are as follows:

File1

Jim
Jack
Tracy*
Michelle

File2

Jim
Jack
Tracy
Michael

diff File1 File2 gives me the following :

< Tracy*
< Michelle
---
> Tracy
> Michael

However,I want diff to ignore the asterix(*) and give the following output :

< Michelle
---
> Michael

Is it possible to do that ?

like image 843
Amistad Avatar asked Apr 23 '13 13:04

Amistad


People also ask

How does diff in Linux work?

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.

Why we use diff command in Linux?

The Linux diff command is used to compare two files line by line and display the difference between them. This command-line utility lists changes you need to apply to make the files identical.

What does diff do in bash?

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

Try

diff -I '*$' FILE1 FILE2

-I RE --ignore-matching-lines=RE

Ignore changes whose lines all match RE

Note: this only works with line ending asterisks.

like image 160
Zsolt Botykai Avatar answered Sep 28 '22 10:09

Zsolt Botykai