Find the common values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find the common values
# 1  
Old 05-24-2013
Find the common values

Hi,

I have two files with the below values.

file1

Code:
305231921      1.0       ben/Ben_Determination_Appeals
1348791394     2.0      ben/Ben_Determination_Appeals]
1305231921     1.0      ben/Cancel_Refund_Payment_JLRS
1348791394     2.0      ben/Cancel_Refund_Payment_JLRS
1305231921     1.0      ben/Cancel_Refund_PERS
1348791394     2.0      ben/Cancel_Refund_PERS

file2

Code:
Ben_Determination_Appeals[2.0]
Cancel_Refund_Payment_JLRS[2.0]
Cancel_Refund_PERS[2.0]

I want the result based on the values of 2nd file. Output should be

Code:
1348791394     2.0      ben/Ben_Determination_Appeals
1348791394     2.0      ben/Cancel_Refund_Payment_JLRS
1348791394     2.0      ben/Cancel_Refund_PERS

# 2  
Old 05-24-2013
Code:
awk 'NR==FNR{a[$1]++;next}
{split($3,b,"/")
s=b[2]"["$2"]"
if (a[s]){print}}' file2 file1

This User Gave Thanks to pravin27 For This Post:
# 3  
Old 05-24-2013
Thanks Pravin. It worked fine. If possible can you please explain the code and also can you let me know from which site i can start learning awk.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find common values in python list in ordered format

Hello All, There are various codes available to find the intersection between two sets in python. But my case is the following: I want to find the continual common pattern in different lists compared to list1. (i have underlined the longest common patterns in set a and set b) a = 2, 3, 5,... (1 Reply)
Discussion started by: Zam_1234
1 Replies

2. Shell Programming and Scripting

Get both common and missing values from multiple files

Hi, I have 5 files with two columns. I need to merge all the 5 files based on column 1. If any of them are missing then corresponding 2nd column should be substituted by missing value. I know hoe to do this for 2 files. but how can I implement for 5 files. I tried this based on 5 files but it... (2 Replies)
Discussion started by: Diya123
2 Replies

3. Shell Programming and Scripting

Find common words

Hi, I have 10 files which needs to be print common words from those all files. Is there any command to find out. (2 Replies)
Discussion started by: munna_dude
2 Replies

4. Shell Programming and Scripting

Common values in 2 columns in 2 files

Hello, Suppose I have these 2 tab delimited files, where the second column in first file contains matching values from first column of the second file, I would like to get an output like this: File A 1 A 2 B 3 C File B A Apple C Cinnabon B Banana I would like... (1 Reply)
Discussion started by: Mohamed EL Hadi
1 Replies

5. Shell Programming and Scripting

Compare multiple files, identify common records and combine unique values into one file

Good morning all, I have a problem that is one step beyond a standard awk compare. I would like to compare three files which have several thousand records against a fourth file. All of them have a value in each row that is identical, and one value in each of those rows which may be duplicated... (1 Reply)
Discussion started by: nashton
1 Replies

6. UNIX for Dummies Questions & Answers

Values with common field in same line with awk

Hi all ! I almost did it but got a small problem. input: cars red cars blue cars green truck black Wanted: cars red-blue-green truck black Attempt: gawk 'BEGIN{FS="\t"}{a = a (a?"-":"")$2; $2=a; print $1 FS $2}' input But I also got the intermediate records... (2 Replies)
Discussion started by: beca123456
2 Replies

7. Shell Programming and Scripting

Find Common Values Across Two Files

Hi All, I have two files like below: File1 MYFILE_28012012_1112.txt|4 MYFILE_28012012_1113.txt|51 MYFILE_28012012_1114.txt|57 MYFILE_28012012_1115.txt|57 MYFILE_28012012_1116.txt|57 MYFILE_28012012_1117.txt|57 File2 MYFILE_28012012_1110.txt|57 MYFILE_28012012_1111.txt|57... (2 Replies)
Discussion started by: angshuman
2 Replies

8. Shell Programming and Scripting

Find common entries

Hi all I have to compare two files and find common entries First file is like this XVY CVY ZYN MNA In second file I have to search these entries in even number of columns 5 XVY 7 hdfj 8 CVY 9 if there is common entries then out put shuld be 5 XVY(approved) 7 hdfj 8... (11 Replies)
Discussion started by: manigrover
11 Replies

9. Shell Programming and Scripting

Parsing common values across multiple files

Hi All, I have multiple (5+) text files with single columns and I would like to grep the common values across all the text files and parse it to a new file. All the values are numerical. Please let me know how to do it using awk. (6 Replies)
Discussion started by: Lucky Ali
6 Replies

10. Shell Programming and Scripting

find common data

Hey guys, I have two files. file1 and file2. file1: a,1 b,2 c,343 d,343 e,4343 f,4544 file 2: a, d, e, Now i need to find the common data between these files from file1. i.e a,1 (8 Replies)
Discussion started by: jaituteja
8 Replies
Login or Register to Ask a Question