Comparision of two data columns in different files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparision of two data columns in different files
# 1  
Old 12-01-2014
Comparision of two data columns in different files

Hi All,

I have a requirement to compare data column which is the last field in two different files and trigger and alert if the difference is greater than 1 for each row.

File1
Code:
Jan   Acount1  2014 11223
Feb  Account2 2014  2345
Mar  Account3 2014 1233

File2
Code:
Jan   Account1 2014 11224
Feb  Account2 2014 2345
Mar  Account3 2014 1239

Can you please help. Thank you.

Last edited by Franklin52; 12-01-2014 at 08:09 AM.. Reason: Please use code tags
# 2  
Old 12-01-2014
Hello Naresh Babu,

Welcome to forum, kindly use the code tags while using commands and codes in the posts please as per forum rules. Kindly go through the forum rules in following link.
https://www.unix.com/misc.php?do=cfrules

Following may help you in same.

Code:
awk -vs1="\"" 'FNR==NR{A=$NF;$NF="";X[$0]=A;Q=FILENAME;next} {B=$NF;$NF=""} ($0 in X){if(B - X[$0] > 1){print FILENAME " column " s1 $0 B s1 " last column has grater value than last colum in " Q " for column " s1 $0 s1}}' File1 File2

Output will be as follows as per given input by you.

Code:
File2 column "Mar Account3 2014 1239" last column has grater value than last colum in File1 for column "Mar Account3 2014 "

EDIT: Just added a bit of code to get the complete columns which have differance more than 1 as follows.

Code:
awk -vs1="\"" 'FNR==NR{A=$NF;$NF="";X[$0]=A;Y[$0]=A;Q=FILENAME;next} {B=$NF;$NF=""} ($0 in X){if(B - X[$0] > 1){print FILENAME " column " s1 $0 B s1 " last column has grater value than last colum in " Q " for column " s1 $0 Y[$0] s1}}' File1 File2

Output will be as follows.
Code:
File2 column "Mar Account3 2014 1239" last column has grater value than last colum in File1 for column "Mar Account3 2014 1233"


Thanks,
R. Singh

Last edited by RavinderSingh13; 12-01-2014 at 02:48 AM.. Reason: Added one more solution a little chang to previous solution
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Gathering data in columns from multiple files

Hello world! I need to gather all the data from different folders and copy it in an one unique text file in columns format. Let me explain, letīs say "a, b, c" are 3 data files of thousands and thousands lines (in the reality, I have nearly one hundred). "a, b, c" are located in the folders... (5 Replies)
Discussion started by: user10600
5 Replies

2. Shell Programming and Scripting

Extracting data from specific rows and columns from multiple csv files

I have a series of csv files in the following format eg file1 Experiment Name,XYZ_07/28/15, Specimen Name,Specimen_001, Tube Name, Control, Record Date,7/28/2015 14:50, $OP,XYZYZ, GUID,abc, Population,#Events,%Parent All Events,10500, P1,10071,95.9 Early Apoptosis,1113,11.1 Late... (6 Replies)
Discussion started by: pawannoel
6 Replies

3. Shell Programming and Scripting

Comparing Select Columns from two CSV files in UNIX and create a third file based on comparision

Hi , I want to compare first 3 columns of File A and File B and create a new file File C which will have all rows from File B and will include rows that are present in File A and not in File B based on First 3 column comparison. Thanks in advance for your help. File A A,B,C,45,46... (2 Replies)
Discussion started by: ady_koolz
2 Replies

4. Shell Programming and Scripting

Compare columns of two files and retrieve data

Hi guys, I need your help. I have two files: file1 1 3 5 file2 1,XX 2,AA 3,BB 4,CC 5,DD I would like to compare the first column and where they are equal to write that output in a new file: 1,XX 3,BB (7 Replies)
Discussion started by: apenkov
7 Replies

5. Shell Programming and Scripting

Comparision of two text files

Dear all, I am having two files big files i need an output file as first occurance of file1 field in file2 example: file1:raju ranifile2:raju|123 raju|879 rani|623 rani|253result:raju|123 rani|623pls help me in this regard (3 Replies)
Discussion started by: suryanarayana
3 Replies

6. Shell Programming and Scripting

awk for selecting columns of different data files

Hello friends, How can I use awk commands to obtain selective blocks from different data files. For example file1 a b c d e f g h i file2 1 2 3 4 5 6 7 8 9 output a b 2 3 d e 5 6 g h 8 9 is it possible ? (2 Replies)
Discussion started by: rpf
2 Replies

7. Shell Programming and Scripting

Columns comparision of two large size files and printing the difference

Hi Experts, My requirement is to compare the second field/column in two files, if the second column is same in both the files then compare the first field. If the first is not matching then print the first and second fields of both the files. first file (a .txt) < 1210018971FF0000,... (6 Replies)
Discussion started by: krao
6 Replies

8. UNIX for Advanced & Expert Users

Comparision of two files.

File Structure file1.txt.arch 029429288,1,,,02087400376,N,02087400376,N,0,02087400376,N,0,0,8010,08000151736,U,N,,08000151736,U,20100726111237,20100726111237,0,20100726111651,00004140,16,16,10,N;... (1 Reply)
Discussion started by: ravigupta2u
1 Replies

9. Shell Programming and Scripting

Column comparision in two files

Hi, I need to compare a column in two different csv files file1 xyz.com,2/2/12,a,b,c eg.com,2/2/23,a,b,ga file2 1,2,ua,xyz.com 1,2,ua,abc.com 1,2,ua,eg.com 1,2,ua,easg.com 1,2,ua,zth.com Read all entries in file1(which has 1000+) and compare column1 of file1 with the column4... (13 Replies)
Discussion started by: nuthalapati
13 Replies

10. Shell Programming and Scripting

comparision of string in various files

i want to take position 19-24(only first line) from all files and need to compare any duplication is there or not. If duplication, then i have to print the file names. I have written to take the characters from 19-24 from all files. but how to compare ? ... (1 Reply)
Discussion started by: senthil_is
1 Replies
Login or Register to Ask a Question