To compare two columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To compare two columns
# 1  
Old 08-16-2013
To compare two columns

I have two pipe delimited files.

File1.txt & File2.txt

File1.txt

Code:
asd|dfg|ghjk
der|eikd|wkd
ret|joiol|wke

File2.txt

Code:
asd|ret|fkkf
ref|hfk|ks
ret|klsd|wr

I need to compare File1 & File2 based on column1 and pass the output to file3.txt( The matching records from File1 should go to File3.txt)

File3.txt should be like this

Code:
asd|dfg|ghjk
der|eikd|wkd
ret|joiol|wke

Can some one help on this

---------- Post updated at 12:42 PM ---------- Previous update was at 11:36 AM ----------

can some one please help !!!!!!
# 2  
Old 08-16-2013
Your description of what you want done and your statement of what should be in File3.txt don't match. If you don't give us a clear description and example of what you want done, we can only waste time guessing at what you want to do.

For the sample input you provided and the sample output you say you want, the simple solution is the following command:
Code:
cp File1.txt File3.txt

A simple way to do what you said you wanted done (ignoring the samples your provided) would be something like:
Code:
awk -F "|" '
FNR == NR {f[$1] = $0;next}
$1 in f {print f[$1]}' File1.txt File2.txt > File3.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to compare two columns in two files?

Hi All, I have a.dat file with content 1,338,30253395122015103,2015103,UB0085000,STMT151117055527002,,, 1,338,30253395122015103,2015103,UB0085000,STMT151117055527001,,, and b.dat having content 1,STMT151117055527001,a1.txt,b1.txt,c1.txt 1,STMT151117055527002,a2.txt,b2.txt,c2.txt ... (13 Replies)
Discussion started by: PRAMOD 96
13 Replies

2. UNIX for Dummies Questions & Answers

Help need to compare columns in files

Hi, Below is my requirement file1 id|cnt 1|1 2|2 3|3 file2 id_1|cnt_1 1|1 2|1 3|1 I want to compare cnt and cnt_1 columns, if they are differ then give the details Am using below awk command, but the output is not as expected. (2 Replies)
Discussion started by: grandhirahuletl
2 Replies

3. Shell Programming and Scripting

Compare 2 csv files by columns, then extract certain columns of matcing rows

Hi all, I'm pretty much a newbie to UNIX. I would appreciate any help with UNIX coding on comparing two large csv files (greater than 10 GB in size), and output a file with matching columns. I want to compare file1 and file2 by 'id' and 'chain' columns, then extract exact matching rows'... (5 Replies)
Discussion started by: bkane3
5 Replies

4. Shell Programming and Scripting

Compare columns in different files

Hi, I have two files like this: 8 1.3 10 1.3 12 1.3 15 1.3 21 1.3 and 1 2 3 4 10 11 15 16 21 22 (3 Replies)
Discussion started by: jamie_123
3 Replies

5. Shell Programming and Scripting

Compare four columns

Hi Friends, I have a dataset like this a b c 1 2 3 4 d e f 4 5 6 7 g h i 1 2 3 7 Now, I would like to write a condition such that either of $4,$5,$6,$7 satisfies that condition, should be printed out with their respective match. For ex, My condition is that either of the values in... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

6. Shell Programming and Scripting

Compare Columns of two files

Hi I have file 1 like this and file 2 like this I need to compare column 3 of both files and delete lines in file1 with same column 3 values in two files. So the output is I tried with perl but didnt work. A perl code will be good as I am learning the language, but any other code would... (1 Reply)
Discussion started by: polsum
1 Replies

7. UNIX for Dummies Questions & Answers

Compare Columns in two files

Hi all, I would like to compare a column in one file to a column in another file and when there is a match it prints the first column and the corresponding second column. Example File1 ABA ABC ABE ABF File 2 ABA 123 ABB 124 ABD 125 ABC 126 So what I would like printed to a file... (0 Replies)
Discussion started by: pcg
0 Replies

8. Shell Programming and Scripting

How to compare two columns in two files?

Hello all, Could someone please let me know shell script or awk solution to compare two columns in two files? Here is the sample - file1.txt abc/xyz,M1234 ddd/lyg,M2345 cnn/tnt,G0123 file2.txt A,abc/xyz,kk,dd,zz,DCT,G0123,1 A,ddd/lyg,kk,dd,zz,DCT,M1234,1... (17 Replies)
Discussion started by: sncoupons
17 Replies

9. Shell Programming and Scripting

Compare few columns from two files

My Friends, Need your help to find the difference between few columns from two comma delimited files. For example, File1 and File2 has 22 columns, and I want to find the difference in first 12 columns. I have list of file names in MyListOfFiles2Compare.txt. Data is separated with commas.... (5 Replies)
Discussion started by: manish44
5 Replies

10. Shell Programming and Scripting

compare file columns

I need help in file comparision. I have two files in below format: FILE_A: ------- COL1 COL2 COL3 COL4 COL5 FILE_B: ------- COL1A COL1B COL1C COL1D COL1E i want to compare for a for each row in FILE_A and FILE_B COL1 of FILE_A with COL1B of FILE_B COL3 of FILE_A with COL1E of... (1 Reply)
Discussion started by: learnoutmore99
1 Replies
Login or Register to Ask a Question