Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Comparing the 2nd column in two different files and printing corresponding 9th columns in new file Post 302527428 by getmmg on Friday 3rd of June 2011 09:17:56 AM
Old 06-03-2011
Columns will be in the order of how the file are given.

Code:
 
perl -lane '$hash{$F[1]}.=" $F[8]";END{print "$_ $hash{$_}" for keys %hash}' file1 file2

And the output is

Code:
ab2  0.0007 0.0037
ab1  0.009 0.019

This User Gave Thanks to getmmg For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing Columns and printing the difference from a particular file

Gurus, I have one file which is having multiple columns and also this file is not always contain the exact columns; sometimes it contains 5 columns or 12 columns. Now, I need to find the difference from that particular file. Here is the sample file: param1 | 10 | 20 | 30 | param2 | 10 |... (6 Replies)
Discussion started by: buzzusa
6 Replies

2. Shell Programming and Scripting

Comparing 2 files with awk and updating 2nd file

file1: (unique files) 1 /pub/atomicbk/catalog/catalog.gif 693 2 /pub/atomicbk/catalog/home.gif 813 3 /pub/atomicbk/catalog/logo2.gif 12871 4 /pub/atomicbk/catalog/sleazbk.html 18338 file2: (duplicate filenames allowed) 28/Aug/1995:00:00:38 1 /pub/atomicbk/catalog/home.gif 813... (2 Replies)
Discussion started by: jontjioe
2 Replies

3. Shell Programming and Scripting

Comparing two files and printing 2nd column if match found

Hi guys, I'm rather new at using UNIX based systems, and when it comes to scripting etc I'm even newer. I have two files which i need to compare. file1: (some random ID's) 451245 451288 136588 784522 file2: (random ID's + e-mail assigned to ID) 123888 xc@xc.com 451245 ... (21 Replies)
Discussion started by: spirm8
21 Replies

4. Shell Programming and Scripting

comparing column of two different files and print the column from in order of 2nd file

Hi friends, My file is like: Second file is : I need to print the rows present in file one, but in order present in second file....I used while read gh;do awk ' $1=="' $gh'" {print >> FILENAME"output"} ' cat listoffirstfile done < secondfile but the output I am... (14 Replies)
Discussion started by: CAch
14 Replies

5. UNIX for Dummies Questions & Answers

Comparing two text files by a column and printing values that do not match

I have two text files where the first three columns are exactly the same. I want to compare the fourth column of the text files and if the values are different, print that row into a new output file. How do I go about doing that? File 1: 100 rs3794811 0.01 0.3434 100 rs8066551 0.01... (8 Replies)
Discussion started by: evelibertine
8 Replies

6. UNIX for Dummies Questions & Answers

Taking the average of two columns and printing it on a new column

Hi, I have a space delimited text file that looks like the following: Aa 100 200 Bb 300 100 Cc X 500 Dd 600 X Basically, I want to take the average of columns 2 and 3 and print it in column 4. However if there is an X in either column 2 or 3, I want to print the non-X value. Therefore... (11 Replies)
Discussion started by: evelibertine
11 Replies

7. Shell Programming and Scripting

Comparing Select Columns from two CSV files in UNIX and create a third file based on comparision

Hi , I want to compare first 3 columns of File A and File B and create a new file File C which will have all rows from File B and will include rows that are present in File A and not in File B based on First 3 column comparison. Thanks in advance for your help. File A A,B,C,45,46... (2 Replies)
Discussion started by: ady_koolz
2 Replies

8. Shell Programming and Scripting

Difference between 2 files, one with 1 column and 2nd file with multiple columns

Hi, I need to find the difference between 2 files in unix and write the result in the new file File1: A B File2: X 123 hajkd Y 345 adjfka A 123 djafjhd B 678 dsndjks Output file: X 123 hajkd Y 345 adjfka Thanks. (6 Replies)
Discussion started by: nani1984
6 Replies

9. Shell Programming and Scripting

Comparing same column from two files, printing whole row with matching values

First I'd like to apologize if I opened a thread which is already open somewhere. I did a bit of searching but could quite find what I was looking for, so I will try to explaing what I need. I'm writing a script on our server, got to a point where I have two files with results. Example: File1... (6 Replies)
Discussion started by: mitabrev83
6 Replies

10. Shell Programming and Scripting

Comparing two columns in two files and printing a third based on a match

Hello all, First post here. I did not notice a previous post to help me down the right path. I am looking to compare a column in a CSV file against another file (which is not a column match one for one) but more or less when a match is made, I would like to append a third column that contains a... (17 Replies)
Discussion started by: dis0wned
17 Replies
pr(1)							      General Commands Manual							     pr(1)

Name
       pr - print files

Syntax
       pr [ options ] [ files ]

Description
       The  command  prints  the  named files on the standard output.  If file is designated by a minus sign (-), or if no files are specified the
       command assumes standard input.	By default, the listing is separated into pages, each headed by the page number, a date and time, and  the
       name of the file.

       By default, columns are of equal width, separated by at least one space.  Lines that do not fit are truncated. However, if the -s option is
       used, lines are not truncated and columns are separated by the separation character.

       If the standard output is associated with a terminal, error messages are withheld until has finished printing.

Options
       The following options can be used singly or in combination:

       -a      Prints multi-column output across the page.

       -b      Prints blank headers.

       -d      Double-spaces the output.

       -eck    Expands input tabs to character positions k+1, 2*k+1, 3*k+1,... n*k+1.  If k is 0 or is omitted, tabs are set at every eighth posi-
	       tion.  Tab characters in the input are expanded into the appropriate number of spaces.  The default for c (any non-digit character)
	       is the tab character; therefore, if c is given, it is treated as the input tab character.

       -f      Uses form-feed character for new pages.	The default is to use a sequence of line-feeds.  The -f option causes the command to pause
	       before beginning the first page if the standard output is associated with a terminal.

       -h      Uses the next argument as the header to be printed instead of the file name.

       -ick    Replaces  white space in output by inserting tabs to character positions k+1, 2*k+1, 3*k+1,...n*k+1.  If k is 0 or is omitted, tabs
	       are set at every eighth position.  The default for c (any non-digit character) is the tab character; therefore, if c is	given,	it
	       is treated as the input tab character.

       +k      Begins printing with page k (default is 1).

       -k      Produces k-column output (default is 1).  The -e and -i options are assumed for multi-column output.

       -lk     Sets the length of a page to k lines.  The default is 66 lines.

       -m      Merges and prints all files simultaneously, one per column (overrides the -k, and -a options).

       -nck    Numbers	lines.	The default for k is 20.  The number occupies the first k+1 character positions of each column of normal output or
	       each line of -m output.	If c, which is any non-digit character is given, it is appended to the line number  to	separate  it  from
	       whatever follows.  The default for c is a tab.

       -ok     Offsets	each line by k character positions (default is 0).  The number of character positions per line is the sum of the width and
	       offset.

       -p      Pauses before beginning each page if the output is directed to a terminal.  The command rings the bell at the terminal and awaits a
	       carriage return.

       -r      Suppresses diagnostic reports on failure to open files.

       -sc     Separates columns by the single character c instead of by the appropriate number of spaces (default for c is a tab).

       -t      Suppresses  the	five-line  identifying header and the five-line trailer normally supplied for each page.  The -t option causes the
	       command to quit printing after the last line of each file without spacing to the end of the page.

       -wk     Sets the width of a line to k character positions.  The default is 72 for equal-width multi-column output; otherwise  there  is	no
	       limit.

Examples
       Print file1 and file2 as a double-spaced, three-column listing with the heading:  file list.
       pr -3dh "file list" file1 file2
       Write file1 on file2, expanding tabs to columns 10, 19, 28, 37,...:
       pr -e9 -t <file1>file2

Files
       /dev/tty* to suspend messages

See Also
       cat(1)

																	     pr(1)
All times are GMT -4. The time now is 04:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy