Sponsored Content
Top Forums Shell Programming and Scripting Perl: Comparing to two files and displaying the differences Post 302564947 by dont_be_hasty on Saturday 15th of October 2011 04:18:22 PM
Old 10-15-2011
Perl: Comparing to two files and displaying the differences

Hi,

I'm new to perl and i have to write a perl script that will compare to log/txt files and display the differences. Unfortunately I'm not allowed to use any complied binaries or applications like diff or comm.

So far i've across a code like this:

Code:
use strict;
use warnings;

my $list1;
my $list2;

my @list1 = qw(111 222 333);
my @list2 = qw(222 333 444);

LIST2: foreach $list2 (@list2){
LIST1: foreach $list1 (@list1){
if ("$list2" eq "$list1") {
next LIST2;
}
}
print "$list2 \n";
}

When I run this I get 444 returned as expected. However I'm wondering how I can change this so that it compares two log or txt files (ie. list1.txt and list2.txt).

Any help at all would be great.

Thanks in advanced.

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags

Last edited by pludi; 10-15-2011 at 05:30 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

comparing file content differences

I need to write a script to find out if there are any .c files created/removed from the last time i monitored the files available. i first created a file to contain all the .c files available on the system. (ls *.c > file1) I created another file using the same command. I used the comm file1... (4 Replies)
Discussion started by: RianTan
4 Replies

2. Shell Programming and Scripting

Comparing files columnwise and print the differences in third file

Hello Everybody!!!!!!!!! Request you to help me with the below mentioned issue: I have 2 files say, File 1: a|4|7 b|3|2 c|8|8 d|8|9 File 2: a|4|6 b|2|2 c|8|8 d|9|8 The third file(output file) should have: Data mismatch in row 1 column 3 Data mismatch in row 2 coumn 2 Data... (3 Replies)
Discussion started by: abhijeet1409
3 Replies

3. Shell Programming and Scripting

Differences between 2 Flat Files and process the differences

Hi Hope you are having a great weeknd !! I had a question and need your expertise for this : I have 2 files File1 & File2(of same structure) which I need to compare on some columns. I need to find the values which are there in File2 but not in File 1 and put the Differences in another file... (5 Replies)
Discussion started by: newbie_8398
5 Replies

4. Shell Programming and Scripting

Comparing two files and list the differences

Hi * I have two text files which has the file size, timestamp and the file name. I need to compare these two files and get the differences in the output format. Can anyone help me out with this. * cat file1.txt *474742 Apr 18* 2010 sample.log *135098 Apr 18* 2010 Testfile 134282 Apr 18* 2010... (7 Replies)
Discussion started by: Sendhil.Kumaran
7 Replies

5. Shell Programming and Scripting

Perl: Need help comparing huge files

What do i need to do have the below perl program load 205 million record files into the hash. It currently works on smaller files, but not working on huge files. Any idea what i need to do to modify to make it work with huge files: #!/usr/bin/perl $ot1=$ARGV; $ot2=$ARGV; open(mfileot1,... (12 Replies)
Discussion started by: mrn6430
12 Replies

6. Shell Programming and Scripting

Help comparing 2 files and sending differences

I have 2 files that need to be compared. Email the differences if something is different and don't email if nothing is different. One or both of the files could be empty. One or both could have data in them. example files backup.doc.$(date +%y%m%d) file size is 0 backup.doc.$(TZ=CST+24... (4 Replies)
Discussion started by: jabbott3
4 Replies

7. Shell Programming and Scripting

Comparing 2 xml files and print the differences only in output

Hi....I'm having 2 xml files, one is having some special characters and another is a clean xml file does not have any special characters. Now I need one audit kind of file which will show me only from which line the special characters have been removed and the special characters. Can you please... (1 Reply)
Discussion started by: Krishanu Saha
1 Replies

8. Shell Programming and Scripting

Need help in comparing two files using shell or Perl

I have these two file that I am trying to compare using shell arrays. I need to find out the changed or the missing enteries from File2. For example. The line "f nsd1" in file2 is different from file1 and the line "g nsd6" is missing from file2. I dont want to use "for loop" because my files... (2 Replies)
Discussion started by: sags007_99
2 Replies

9. Shell Programming and Scripting

Comparing fields of two files and displaying results

Hello , I am trying to compare two files i.e one master file and the other exclusion file. If the second field of masterfile is oracle8 then I need to compare the 3rd field of master file with the 1st field of all the rows of exclusion file else I need to compare 2nd field from master file with... (2 Replies)
Discussion started by: rahul2662
2 Replies

10. UNIX for Beginners Questions & Answers

Comparing time differences between 2 Solaris servers

Good day to all. I'm relatively new in using the Sun Solaris OS. I would like to request your expertise in helping to solve a problem that I have at work. Not sure if this has been asked before but I have tried searching through the internet to no avail. Basically I have 2 sun solaris... (8 Replies)
Discussion started by: Fossil_84
8 Replies
SGMLDIFF(1)															       SGMLDIFF(1)

NAME
sgmldiff - Find differences in the markup of two SGML files SYNOPSIS
sgmldiff [ options ... ] file1 file2 [ -a | --attributes | -c [ attributes | nesting | textpos ] | --context [ attributes | nesting | textpos ] | -s | --statistics | -h | --help | -v | --version ] DESCRIPTION
This perl script allows to determine the structural differences between two SGML files. It compares the files, regardless of what is in between the tags, to only focus on the markup. Its output is similar to diff(1). The typical use of sgmldiff is to compare an SGML file with its translation into another language. If the translation was done cleanly, sgmldiff returns without finding any difference in the markup. An example of a typical call to sgmldiff is: sgmldiff english.sgml italiano.sgml If there are differences in markup between both files, sgmldiff will output a series of differences reports summarized with lines of the form: 169a164 At line 169 of the first file, line 164 of the second file has been added. 8a12,15 At line 8 of the first file, lines 12 to 15 of the second file have been added. 41d28 Line 41 of the first file has been destroyed, to obtain line 28 of the second file. 63,66d61 Lines 63 to 66 of the first file have been destroyed. to obtain line 61 of the second file. 52c51 Line 52 of the first file has been changed into line 51 of the second file. 5,7c8,10 Lines 5 to 7 of the first file have been changed into lines 8 to 10 of the second line. In addition to those summaries, the lines of the first file are shown preceeded by '<' and the lines of the second file are shown preceeded by '>". OPTIONS
Here is the list of actions that can be requested to sgmldiff: [ -a | --attributes ] Include the attribute values in the difference tests. Don't set this value if the attributes are likely to be translated. Set this value if the attributes value shouldn't change between both files. Default is to don't include the attributes in the difference tests. [ -c [ attributes | nesting | textpos ] | --context [ attributes | nesting | textpos ] ] Add more context to the difference. Since every test between the tags is removed before testing the differences, sgmldiff is likely to resynchronize itself at the wrong place, by thinking the location in both files correspond, while it's not true. By adding more context to the compared area, such risk is disminished. The allowed values for the --context option are: attributes Take into account the attribute names. The attribute values are controlled by the attributes option. nesting Take into account the nesting level of all the compared tags. textpos Take into account the position in the text. [ -s | --statistics ] Print some SGML information at the end. [ -h | --help ] Print a short help message and exit [ -v | --version ] Print the version identifier and exit FILES
AUTHORS
Frederik Fouvry Developer of sgmldiff. SEE ALSO
jw(1) conversion from a SGML file to other file formats nsgmls(1) a base component of Jade DSSSL engine http://sources.redhat.com/docbook-tools/ <URL:http://sources.redhat.com/docbook-tools/> the home page of the DocBook tools, a compendium of all tools necessary to process DocBook files, including the DocBook-utils 12 September 2012 SGMLDIFF(1)
All times are GMT -4. The time now is 04:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy