Sponsored Content
Top Forums Shell Programming and Scripting print when column match with other file Post 302599374 by attila on Friday 17th of February 2012 01:47:12 AM
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
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
comm(1) 							   User Commands							   comm(1)

NAME
comm - select or reject lines common to two files SYNOPSIS
comm [-123] file1 file2 DESCRIPTION
The comm utility reads file1 and file2, which must be ordered in the current collating sequence, and produces three text columns as output: lines only in file1; lines only in file2; and lines in both files. If the input files were ordered according to the collating sequence of the current locale, the lines written will be in the collating sequence of the original lines. If not, the results are unspecified. OPTIONS
The following options are supported: -1 Suppresses the output column of lines unique to file1. -2 Suppresses the output column of lines unique to file2. -3 Suppresses the output column of lines duplicated in file1 and file2. OPERANDS
The following operands are supported: file1 A path name of the first file to be compared. If file1 is -, the standard input is used. file2 A path name of the second file to be compared. If file2 is -, the standard input is used. USAGE
See largefile(5) for the description of the behavior of comm when encountering files greater than or equal to 2 Gbyte ( 2^31 bytes). EXAMPLES
Example 1 Printing a list of utilities specified by files If file1, file2, and file3 each contain a sorted list of utilities, the command example% comm -23 file1 file2 | comm -23 - file3 prints a list of utilities in file1 not specified by either of the other files. The entry: example% comm -12 file1 file2 | comm -12 - file3 prints a list of utilities specified by all three files. And the entry: example% comm -12 file2 file3 | comm -23 -file1 prints a list of utilities specified by both file2 and file3, but not specified in file1. ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of comm: LANG, LC_ALL, LC_COLLATE, LC_CTYPE, LC_MESSAGES, and NLSPATH. EXIT STATUS
The following exit values are returned: 0 All input files were successfully output as specified. >0 An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWesu | +-----------------------------+-----------------------------+ |CSI |enabled | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
cmp(1), diff(1), sort(1), uniq(1), attributes(5), environ(5), largefile(5), standards(5) SunOS 5.11 3 Mar 2004 comm(1)
All times are GMT -4. The time now is 07:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy