print when column match with other file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting print when column match with other file
# 1  
Old 02-17-2012
print when column match with other file

Hello all, please help. There are two file like this:

file1:

Code:
1197510.0    294777.7  9666973.0                          21.6      1839.8
 1197510.0    294777.7  9666973.0                         413.2      2075.9
 1197510.0    294777.7  9666973.0                         689.3      2260.0
 1197510.0    294777.7  9666973.0                         955.4      2431.9 
 1197532.0    295017.3  9667342.0                          49.2      1884.5
 1197532.0    295017.3  9667342.0                         351.6      2043.2
 1197554.0    295257.0  9667711.0                         420.7      2092.8
 1197576.0    295496.6  9668080.0                         365.5      2057.2      
 1197576.0    295496.6  9668080.0                         669.2      2250.0      
 1197576.0    295496.6  9668080.0                         902.7      2401.4

file2:

Code:
10007 4018 9666973.0
10029 4018 9667342.0
10051 4018 9667711.0
10073 4018 9668080.0

if 3rd column of file1 match with 3rd column of file2, print like this:

Code:
1197510.0    294777.7  9666973.0      4018     10007      21.6      1839.8
 1197510.0    294777.7  9666973.0      4018     10007     413.2      2075.9
 1197510.0    294777.7  9666973.0      4018     10007     689.3      2260.0
 1197510.0    294777.7  9666973.0      4018     10007     955.4      2431.9 
 1197532.0    295017.3  9667342.0      4018     10029      49.2      1884.5
 1197532.0    295017.3  9667342.0      4018     10029     351.6      2043.2
 1197554.0    295257.0  9667711.0      4018     10051     420.7      2092.8
 1197576.0    295496.6  9668080.0      4018     10073     365.5      2057.2
 1197576.0    295496.6  9668080.0      4018     10073     669.2      2250.0
 1197576.0    295496.6  9668080.0      4018     10073     902.7      2401.4

thank in advance,

-attila
# 2  
Old 02-17-2012
Code:
join -1 3 -2 3 file1 file2 | awk '{print $2,$3,$1,$7,$6,$4,$5}' OFS="\t"

Guru.
This User Gave Thanks to guruprasadpr For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare 1st column from 2 file and if match print line from 1st file and append column 7 from 2nd

hi I have 2 file with more than 10 columns for both 1st file apple,0,0,0...... orange,1,2,3..... mango,2,4,5..... 2nd file apple,2,3,4,5,6,7... orange,2,3,4,5,6,8... watermerlon,2,3,4,5,6,abc... mango,5,6,7,4,6,def.... (1 Reply)
Discussion started by: tententen
1 Replies

2. Shell Programming and Scripting

Input file needs to match a column and print the entire line

I have a file with class c IP addresses that I need to match to a column and print the matching lines of another file. I started playing with grep -if file01.out file02.out but I am stuck as to how to match it to a column and print the matching lines; cat file01.out 10.150.140... (5 Replies)
Discussion started by: lewk
5 Replies

3. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

4. Shell Programming and Scripting

awk strings search + print next column after match

Hi, I have a file filled with search strings which have a blank in between and look like this: S. g. Ehr. o. Jg. v. d. Chijs g. Ehr. Now i would like to search for the strings and it also shall return the next column after the match. awk -v FILE="search_strings.txt" 'BEGIN {... (10 Replies)
Discussion started by: sdf
10 Replies

5. Shell Programming and Scripting

print column value after exact match of variables in file

I have file like below summit hvar_rgrpd_10d_hvams17_ _kgr_prod.rec checksum checksum us europe summit hvar_rgrpd_10d_hvams17_ _kgr_prod.xml var summit us ... (5 Replies)
Discussion started by: manas_ranjan
5 Replies

6. Shell Programming and Scripting

Match a line in File 1 with Column in File 2 and print whole line in file 2 when matched

Hi Experts, I am very new to scripting and have a prb since few days and it is urgent to solve so much appreciated if u help me. i have 2 files file1.txt 9647810043118 9647810043126 9647810043155 9647810043161 9647810043166 9647810043185 9647810043200 9647810043203 9647810043250... (22 Replies)
Discussion started by: mustafa.abdulsa
22 Replies

7. Shell Programming and Scripting

Match and print particular column

Hi All, I am in need of help. I want to match a value of each row in “file 1” with the value of first row in “file 2” and print out only the columns that match. How can I do it in awk? Any help is greatly appreciated. for example, I have two files: Cat “File 1” ID 3 8 15 Cat “File... (2 Replies)
Discussion started by: newpro
2 Replies

8. Shell Programming and Scripting

Strings from one file which exactly match to the 1st column of other file and then print lines.

Hi, I have two files. 1st file has 1 column (huge file containing ~19200000 lines) and 2nd file has 2 columns (small file containing ~6000 lines). ################################# huge_file.txt a a ab b ################################## small_file.txt a 1.5 b 2.5 ab ... (4 Replies)
Discussion started by: AshwaniSharma09
4 Replies

9. Shell Programming and Scripting

print column that match reg expr

Hi all, I want to cut a column which match the regular expression "beta", if I don't know the column number? cat test alpha;beta;gamma 11;22;33 44;55;66 77;88;99 should be command .... beta 22 55 (6 Replies)
Discussion started by: research3
6 Replies

10. Shell Programming and Scripting

Awk+Grep Input file needs to match a column and print the entire line

I'm having problems since few days ago, and i'm not able to make it works with a simple awk+grep script (or other way to do this). For example, i have a input file1.txt: cat inputfile1.txt 218299910417 1172051195 1172070231 1172073514 1183135117 1183135118 1183135119 1281440202 ... (3 Replies)
Discussion started by: poliver
3 Replies
Login or Register to Ask a Question