Match the records in two files.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Match the records in two files.
# 1  
Old 01-26-2009
Match the records in two files.

Hi all please give me the solution for this im stuck somewhere.

I have two files A and B
file A has 300 records as
000.aud
111.aud
.
.
.
300.aud

file B has 213 records randomly
005.aud
176.aud
.
.
.
200.aud

I want to match similar 213 records in file B from file A.
Please dont use the diff A B > C command I tryd it its difficult to find the matches help with some other command please.

Regards
Anwar.
# 2  
Old 01-26-2009
Code:
awk ' FILENAME=="A" {arr[$0]++}
        FILENAME=="B" { if ($0 in arr) {print $0} } '  A   B  > duplicate.lis

# 3  
Old 01-26-2009
Hammer & Screwdriver

Perhaps the comm command would help you.

Code:
sort file1 >file1.tmp
sort file2 >file2.tmp
comm -12 file1.tmp file2.tmp
rm file1.tmp file2.tmp

Those commands should show you the common lines between you two input files (called file1 and file2).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Data match 2 files based on first 2 columns matching only and join if match

Hi, i have 2 files , the data i need to match is in masterfile and i need to pull out column 3 from master if column 1 and 2 match and output entire row to new file I have tried with join and awk and i keep getting blank outputs or same file is there an easier way than what i am... (4 Replies)
Discussion started by: axis88
4 Replies

2. Shell Programming and Scripting

Replace multiple positions in records which match crireria

I have a test file a.txt 001 123 456 789 002 This is just a 001 test data 003 file. I want to clear columns 5 and 6 if the first 3 characters are 001 using awk. I tried following but does not work. Any suggestions? awk 'BEGIN{OFS=FS=""} {if (substr($0,1,3)=="123") $5=" "; $6="... (20 Replies)
Discussion started by: Soham
20 Replies

3. Shell Programming and Scripting

awk to match field between two files and use conditions on match

I am trying to look for $2 of file1 (skipping the header) in $2 of file2 (skipping the header) and if they match and the value in $10 is > 30 and $11 is > 49, then print the line from file1 to a output file. If no match is foung the line is not printed. Both the input and output are tab-delimited.... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

Compare two files with different number of records and output only the Extra records from file1

Hi Freinds , I have 2 files . File 1 |nag|HYd|1|Che |esw|Gun|2|hyd |pra|bhe|3|hyd |omu|hei|4|bnsj |uer|oeri|5|uery File 2 |nag|HYd|1|Che |esw|Gun|2|hyd |uer|oi|3|uery output : (9 Replies)
Discussion started by: i150371485
9 Replies

5. Shell Programming and Scripting

Deleting duplicate records from file 1 if records from file 2 match

I have 2 files "File 1" is delimited by ";" and "File 2" is delimited by "|". File 1 below (3 record shown): Doc1;03/01/2012;New York;6 Main Street;Mr. Smith 1;Mr. Jones Doc2;03/01/2012;Syracuse;876 Broadway;John Davis;Barbara Lull Doc3;03/01/2012;Buffalo;779 Old Windy Road;Charles... (2 Replies)
Discussion started by: vestport
2 Replies

6. Shell Programming and Scripting

Match records from multiple files

Hi, I have 3 tab delimited text files which look like this. File1: PROTEINID DESCRIPTION PEPTIDES FRAMES GB://115298678 _gi_115298678_ref_NP_000055.2_ complement C3 precursor 45 55 GB://4502027 _gi_4502027_ref_NP_000468.1_ serum albumin preproprotein 34 73 Entrez://strain 11128 /... (3 Replies)
Discussion started by: Vavad
3 Replies

7. Shell Programming and Scripting

Extract data from records that match pattern

Hi Guys, I have a file as follows: a b c 1 2 3 4 pp gg gh hh 1 2 fm 3 4 g h i j k l m 1 2 3 4 d e f g h j i k l 1 2 3 f 3 4 r t y u i o p d p re 1 2 3 f 4 t y w e q w r a s p a 1 2 3 4 I am trying to extract all the 2's from each row. 2 is just an example... (6 Replies)
Discussion started by: npatwardhan
6 Replies

8. Shell Programming and Scripting

awk partial match and filter records

Hi, I am having file which contains around 15 columns, i need to fetch column 3,12,14 based on the condition that column 3 starts with 40464 this is the sample data how to achieve that (3 Replies)
Discussion started by: aemunathan
3 Replies

9. Shell Programming and Scripting

AWK, print no of records after pattern match.

Hi ALL :). i have a file, cat 3 + dog 5 + rat 6 - i want to print no of record having pattern "+". thanks in advance :confused:. (2 Replies)
Discussion started by: admax
2 Replies

10. UNIX for Advanced & Expert Users

Match the string and copy records to another location

Hi, I have particular set of files which have the below contents: ****** PBX TYPE:ID6 PBX-id: A11 rolled on 123456 368763 00 >>>>>> A11,2008-07-01 21:31:00.000,42,42112, ,XXXXXXXX A11,2008-07-01 21:40:00.000,6, , ,XXXXXXX A12,2008-07-01 21:53:00.000,68, , ,XXXXXXXX... (12 Replies)
Discussion started by: bsandeep_80
12 Replies
Login or Register to Ask a Question