compare two col from 2 files, and output uniq from file 1


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting compare two col from 2 files, and output uniq from file 1
# 1  
Old 01-09-2008
compare two col from 2 files, and output uniq from file 1

Hi,
I can't find how to achive such thing, please help.
I have try with uniq and comm but those command can't compare columns just whole lines,
I think awk will be the best but awk is magic for me as of now.

file a
a1~a2~a3~a4~a6~a7~a8

file b
b1~b2~b3~b4~b6~b7~b8

output 1:
compare columns 3 from files a and b
print all lines from file a where where column a3 is present in file b as b3
a1~a2~a3~a4~a6~a7~a8

Regards
Peter
# 2  
Old 01-10-2008
awk '{print $3}' file.name > new.file.name
then the same for the second file, but append the result, and then "uniq -d" which will print only the duplicates.
# 3  
Old 01-10-2008
Do you want this?

Code:
awk 'NR==FNR{x[$3];next}$3 in x' FS="~" fileB fileA

Use nawk or /usr/xpg4/bin/awk on Solaris.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare 2 files the send output to a file

Hallo Friends, I would like to compare two files, then write the difference between the two into output file then find a pattern then search for that pattern. -bash-3.2$ cat BS_Orig_20141112.csv|head -20 BW0159574451211141638275086@196.35.130.5 BW02043750712111491637691@196.35.130.5... (2 Replies)
Discussion started by: kekanap
2 Replies

2. UNIX for Dummies Questions & Answers

To compare two files,Output into a new file

Hi Please help me to compare two files and output into a new file file1.txt 15114933 |4001 15291649 |933502 15764675 |4316 15764678 |4316 15761974 |282501 15673104 |933505 15673577 |933505 15673098 |933505 15673096 |933505 15673092 |933505 15760705 ... (13 Replies)
Discussion started by: Ankita Talukdar
13 Replies

3. UNIX for Dummies Questions & Answers

Compare two files and output to new file

Hi, Please help How to compare two files- Any mismatches 2nd and 3rd column's values corresponding to 1st column. file1 15294024|Not Allowed|null 15291398|Not Allowed|null 15303292|Dropship (standard)|N 15303291|Dropship (standard)|N 15275561|Store Only|Y 15275560|Store Only|Y... (2 Replies)
Discussion started by: Ankita Talukdar
2 Replies

4. Shell Programming and Scripting

Run a program-print parameters to output file-replace op file contents with max 4th col

Hi Friends, This is the only solution to my task. So, any help is highly appreciated. I have a file cat input1.bed chr1 100 200 abc chr1 120 300 def chr1 145 226 ghi chr2 567 600 unix Now, I have another file by name input2.bed (This file is a binary file not readable by the... (7 Replies)
Discussion started by: jacobs.smith
7 Replies

5. Shell Programming and Scripting

awk - getting uniq count on multiple col

Hi My file have 7 column, FIle is pipe delimed Col1|Col2|col3|Col4|col5|Col6|Col7 I want to find out uniq record count on col3, col4 and col2 ( same order) how can I achieve it. ex 1|3|A|V|C|1|1 1|3|A|V|C|1|1 1|4|A|V|C|1|1 Output should be FREQ|A|V|3|2 FREQ|A|V|4|1 Here... (5 Replies)
Discussion started by: sanranad
5 Replies

6. Shell Programming and Scripting

Compare two files and output in another file

I have two files ' 1st one ALIC-000352-B ALIC-000916-O DDS-STNGD FDH-PPO1-001 PFG-30601-001 2nd one 'ALIC-000352-B' 'ALIC-000916-O' 'DDS-STNGD' 'FDH-PPO1-001' (4 Replies)
Discussion started by: Pratik4891
4 Replies

7. Shell Programming and Scripting

Compare - 1st col of file

Hi, I have two different files, one has two columns and other has only one column. I would like to compare the first column in the first file with the data in the second file and write a third file with the data that is not present is not common to them. First file:... (26 Replies)
Discussion started by: swame_sp
26 Replies

8. 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

9. Shell Programming and Scripting

Compare 2 files and give uniq output

Hi , Just to find out a way to compare these 2 files and give unique output. For eg: 1.txt contains 1 2 3 4 5 6 -------------------------------------- 2.txt contains 1 2 6 8 (1 Reply)
Discussion started by: rauphelhunter
1 Replies

10. UNIX for Dummies Questions & Answers

compare 2 files, output dups to file

I have two files that I want to compare and output a new file that will contain the duplicates. I have tried comm -12 and it doesn't work? Any help will be helpful. Thanks, Barbara (2 Replies)
Discussion started by: blt123
2 Replies
Login or Register to Ask a Question