Sponsored Content
Top Forums Shell Programming and Scripting compare 2 coloum of 2 diff files using perl script Post 302219740 by era on Wednesday 30th of July 2008 01:37:05 AM
Old 07-30-2008
And here is (roughly) the same in Perl:

Code:
perl -ane 'BEGIN { open FILE1, ">file1.both"; open FILE2, ">file2.both"; }
  if ($. == ++$n) { $h{$F[2]} = $_; close ARGV if eof; next; }
  if ($h{$F[2]}) { print FILE1 $h{$F[2]}; print FILE2; }' file1 file2

This isn't very idiomatic Perl, but should hopefully be enough to get you started. The trickery with $n and ARGV is to simulate the awk NR==FNR idiom. The eof thing is to reset line numbers in $. when the file changes; see the eof documentation for a brief discussion.

By the way, $3 in 6515152 52272 * ConstMethodKlass is just "*" -- maybe you want to normalize that, rather than change the script.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare two files and output diff to third file

I have made several attempts to read two files of ip addresses and eliminate records from file1 that are in file2. My latest attempt follows. Everything works except my file3 is exactly the same as file1 and it should not be. # !/usr/bin/bash # # NoInterfaces # Utility will create a file... (8 Replies)
Discussion started by: altamaha
8 Replies

2. Shell Programming and Scripting

add coloum value based on first coloum

Hi i have a file and i want to add the coloum values like 9067 is coming twice here so o/p willbe like 9067,sum of 3rd coloum,sum of 4th coloum 9015 is coming 0nce then o/p 9015,15,6 sum is happening based on first coloum it will add all the third coloum and 4th coloum value where first... (1 Reply)
Discussion started by: aaysa123
1 Replies

3. Shell Programming and Scripting

compare two files, diff the result

Hi Everyone, 1.txt 00:01:01 asdf 00:33:33 1234 00:33:33 0987 00:33:33 12 00:33:33 444 2.txt vvvv|ee 444|dd33|ee dddd|ee 12|ee 3ciur|fdd the output should be: (6 Replies)
Discussion started by: jimmy_y
6 Replies

4. Shell Programming and Scripting

Using Diff to Compare 2 files

Hi I've been trying various methods that I have found online with regards to comparing 2 files using the diff command. Nothing seems to work. The problem is that I'm not too familiar with the proper syntax. Can you please assist me. Here is my script: #!/bin/bash awk -F',' -v file1="$1"... (9 Replies)
Discussion started by: ladyAnne
9 Replies

5. Shell Programming and Scripting

Perl script to compare two files

hi, As such I am new to perl on google search I found a code for Perl script to compare two files and print differences between them and instead of prinintg I want to store the diff. in a outputfile so can sombody provide assistance upon this from where can I edit in script to store the diff in... (1 Reply)
Discussion started by: dinesh.4126
1 Replies

6. Shell Programming and Scripting

Need Perl script to compare two CSV files

Need perl script to compare the two CSV files and and give out put in CSV format File MsPMTP.csv File ProfileNames.csv MsPMTP.csv is having lines like below JBL_VIJ_A_A962/r01sr4sl12/port#01-#13-Au4P-4c-TMi-PMNETR15 JBL_VIJ_A_A962/r01sr4sl12/port#01-#13-Au4P-4c-TMi-PMFETR15... (9 Replies)
Discussion started by: sreedhargouda
9 Replies

7. Shell Programming and Scripting

Shell script to compare ,diff and remove betwen 2 files

Hi Friends Need your expertise. Command to check the difference and compare 2 files and remove lines . example File1 is master copy and File2 is a slave copy . whenever i change, add or delete a record in File1 it should update the same in slave copy . Can you guide me how can i accomplish... (3 Replies)
Discussion started by: ajayram_arya
3 Replies

8. Shell Programming and Scripting

Compare two CSV files and put the difference in third file with line no,field no and diff value.

I am having two csv files i need to compare these files and the output file should have the information of the differences at the field level. For Example, File 1: A,B,C,D,E,F 1,2,3,4,5,6 File 2: A,C,B,D,E,F 1,2,4,5,5,6 out put file: (12 Replies)
Discussion started by: karingulanagara
12 Replies

9. Shell Programming and Scripting

Diff of 2 files using perl

Assitance needed in checking file difference using a perl script Below is the example I wanted a report saying file2 has an update of new value. File1 old date Alpha 156 Beta 255 Gama 6987 segma 4578 File2 new date Alpha 156 Beta 255 Gama 1000 (3 Replies)
Discussion started by: ajayram_arya
3 Replies
JOIN(1) 						      General Commands Manual							   JOIN(1)

NAME
join - relational database operator SYNOPSIS
join [-an] [-e s] [-o list] [-tc] file1 file2 DESCRIPTION
Join forms, on the standard output, a join of the two relations specified by the lines of file1 and file2. If file1 is `-', the standard input is used. File1 and file2 must be sorted in increasing ASCII collating sequence on the fields on which they are to be joined, normally the first in each line. There is one line in the output for each pair of lines in file1 and file2 that have identical join fields. The output line normally con- sists of the common field, then the rest of the line from file1, then the rest of the line from file2. Fields are normally separated by blank, tab or newline. In this case, multiple separators count as one, and leading separators are dis- carded. These options are recognized: -an In addition to the normal output, produce a line for each unpairable line in file n, where n is 1 or 2. -e s Replace empty output fields by string s. -o list Each output line comprises the fields specified in list, each element of which has the form n.m, where n is a file number and m is a field number. -tc Use character c as a separator (tab character). Every appearance of c in a line is significant. SEE ALSO
sort(1), comm(1), awk(1). BUGS
With default field separation, the collating sequence is that of sort -b; with -t, the sequence is that of a plain sort. The conventions of join, sort, comm, uniq, look and awk(1) are wildly incongruous. 7th Edition April 29, 1985 JOIN(1)
All times are GMT -4. The time now is 04:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy