How to find the difference between 2 files in a shell script

There are 100 files in the directory and there are 2 pairs of files.

I want to find the difference between two files in a shell script

File 1: 
Operating System : Windows XP
Operating System : Windows NT
Operating System : Windows 2008

FILE 2: 
Windows XP
Windows NT
Windows2008

(for example, Windows 2008 (file 1) and Windows2008 (file 2)).

But finally, both files make no difference.

How to do it?

This file is in the linux host and want to make a shell script?

+3
source share
4 answers

You can use Perl and diff, right? cutnot doing this job. Fidelity to your original comment, I am going to search for the word that appears after the "Widnows" in each input line and create a new file consisting only of these words. Then I'm going to split the files.

, Perl, , StackOverflowers, . , Perl. , , . downvotes, .

-, Perl script ( preparse.pl):

my $f = shift @ARGV;
open FILE, "<$f" or die("Couldn't open file!");
while (<FILE>) {
    print "$1\n" if $_ =~ /Widnows(\s?)*?(\S+)\s*/;
}

:

preparse.pl file1 > file1.tmp
preparse.pl file2 > file2.tmp
diff file1.tmp file2.tmp

Perl script. .

+2

diff , -u.

$ diff -u file1 file2
--- file1   2010-07-14 02:08:20.000000000 -0700
+++ file2   2010-07-14 02:08:29.000000000 -0700
@@ -1,3 +1,3 @@
-Operating System : Windows XP
-Operating System : Windows NT
-Operating System : Windows 2008
+Windows XP
+Windows NT
+Windows2008

diff, , wdiff:

$ wdiff file1 file2
[-Operating System :-]Windows XP
[-Operating System :-]
Windows NT
[-Operating System : Windows 2008-]
{+Windows2008+}

, , xxdiff  kdiff3 . ( ).

-, , cmp diff :

$ cmp -l file1 file2
 1 117 127
 2 160 151
 3 145 156
...

cmp , .

+2

The question is too inaccurate, but try the following:

diff <(sed 's/Operating System : //' file1.txt) file2.txt
+1
source

I would use diff, diff3 if you are comparing 3 files with each other or vimdiff.

+1
source

Source: https://habr.com/ru/post/1754567/


All Articles