There are 100 files in dir and there are 2 pairs of file.
I want to find the difference between 2 files in shell script
File 1:
Operating System : Windows XP
Operating System : Windows NT
Operating System : Windows 2008
FILE 2:
Windows XP
Windows NT
Windows2008
( e.g Windows 2008 ( file 1 ) and Windows2008 ( file2) ) .
But finally both file dont have any difference.
How to achieve this?
These file in linux host and want to do shell script ?
Let's use Perl and diff, shall we? cut doesn't quite do the job. In faithfulness to your original comment, I'm going to look for the word that comes after 'Widnows' in each line of input, and create a new file consisting of only those words. Then I'm going to diff the files.
Every time I've posted Perl, every single time, I've had a swarm of StackOverflowers criticize it. So, get ready for some bad Perl. It will probably work. My reputation can take the downvotes, and I really want to be helpful here.
First, the Perl script (call it 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*/;
}
Now, the command you run:
preparse.pl file1 > file1.tmp
preparse.pl file2 > file2.tmp
diff file1.tmp file2.tmp
Feel free to make this one big Perl script. Whatever.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With