Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Matching 2 files based on key Post 303030720 by Corona688 on Thursday 14th of February 2019 02:43:28 PM
Old 02-14-2019
You're giving it file_1 first, which isn't the file containing the keys to match with, and later, matching against column 1 of the other wrong file.

So, let's try saving the keys from file_2, then matching them with the second column of file_1:

Code:
awk 'NR==FNR{a[$1];next} ($2 in a)' file_2.txt file_1.txt > output.txt

This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

merging two files based on some key

I have to merge two files: The files are having the same format like A0this is first line TOlast line silmilarly other lines. I have to search for A0 line in the second file also and then put the data in the third file under A0 heading ,then for A1 and so on. A0 portion will be treminated... (1 Reply)
Discussion started by: Vandana Yadav
1 Replies

2. Shell Programming and Scripting

Merge files based on key

Hi Friends, Can any one help me with merging these file based on two columns : File1: A|123|99|SAMS B|456|95|GEORGE D|789|85|HOVARD File2: S|123|99|NANcY|6357 S|123|99|GREGRO|83748 A|456|95|HARRY|827|somers S|456|95|ANTONY|546841|RUDOLPH|7263 B|456|95|SMITH|827|BOISE STATE|834... (3 Replies)
Discussion started by: sbasetty
3 Replies

3. Shell Programming and Scripting

joining files based on key column

Hi I have to join two files based on 1st column where 4th column of a2.txt=at and take 2nd column of a1.txt and 3rd column of a2.txt and check against source files ,if matches list those source file names. a1.txt a1|20090809|20090810 a2|20090907|20090908 a2.txt a1|d|file1.txt|at... (9 Replies)
Discussion started by: akil
9 Replies

4. Shell Programming and Scripting

Matching 2 files based on one column

Hi, On a similar subject, the following. I have two files: file1.txt dbSNP_rsID,Chromosome,Position,Gene rs10399749,chr. 01,45162,? rs4030303,chr. 01,72434,? rs4030300,chr. 01,72515,? rs940550,chr. 01,78032,? rs13328714,chr. 01,81468,? rs11490937,chr. 01,222077,? rs6683466,chr.... (5 Replies)
Discussion started by: swvanderlaan
5 Replies

5. Shell Programming and Scripting

Merge two files based on a 3rd key file

Hi, I want to merge the two files based on the key file's columns. The key file: DATE~DATE HOUSE~IN_HOUSE CUST~IN_CUST PRODUCT~PRODUCT ADDRESS~CUST_ADDR BASIS_POINTS~BASIS_POINTS ... The other 2 files are From_file & To_file - The From_file: DATE|date/time|29|9 ... (9 Replies)
Discussion started by: dips_ag
9 Replies

6. UNIX for Dummies Questions & Answers

How to fetch files right below based on some matching criteria?

I have a requirement where in i need to select records right below the search criteria qwertykeyboard white 10 20 30 30 40 50 60 70 80 qwertykeyboard black 40 50 60 70 90 100 qwertykeyboard and white are headers separated by a tab. when i execute my script..i would be searching... (4 Replies)
Discussion started by: vinnu10
4 Replies

7. UNIX for Dummies Questions & Answers

Merge selective columns from files based on common key

Hi, I am trying to selectively merge two files based on keys reported in the 1st column. File1: #file1-header1 file1-header2 111 qwe rtz uio 198 asd fgh jkl 165 yxc 789 poi uzt rew 89 lkj File2: #file2-header2 file2-header2 165 ghz nko2 ... (2 Replies)
Discussion started by: dovah
2 Replies

8. Shell Programming and Scripting

awk - Merge two files based on one key

Hi, I am struggling with the an awk command to merge two files based on a common key. I want to append the value from File2 ($2) onto the end of File1 where $1 from each file matches - If no match then nothing is apended File1 COL1|COL2|COL3|COL4|COL5|COL6|COL7... (3 Replies)
Discussion started by: Ads89
3 Replies

9. Shell Programming and Scripting

Files summary using awk based on index key

Hello , I have several files which are looking similar to : file01.txt keyA001 350 X string001 value001 keyA001 450 X string002 value007 keyA001 454 X string002 value004 keyA001 500 X string003 value005 keyA001 255 X string004 value006 keyA001 388 X string005 value008 keyA001 1278 X... (4 Replies)
Discussion started by: alex2005
4 Replies

10. UNIX for Beginners Questions & Answers

Match tab-delimited files based on key

I thought I had this figured out but was wrong so am humbly asking for help. The task is to add an additional column to FILE 1 based on records in FILE 2. The key is in COLUMN 1 for FILE 1 and in COLUMN 1 OR COLUMN 2 for FILE 2. I want to add the third column from FILE 2 to the beginning of... (8 Replies)
Discussion started by: andmal
8 Replies
Imager::Color(3pm)					User Contributed Perl Documentation					Imager::Color(3pm)

NAME
Imager::Color - Color handling for Imager. SYNOPSIS
use Imager; $color = Imager::Color->new($red, $green, $blue); $color = Imager::Color->new($red, $green, $blue, $alpha); $color = Imager::Color->new("#C0C0FF"); # html color specification $color->set($red, $green, $blue); $color->set($red, $green, $blue, $alpha); $color->set("#C0C0FF"); # html color specification ($red, $green, $blue, $alpha) = $color->rgba(); @hsv = $color->hsv(); $color->info(); if ($color->equals(other=>$other_color)) { ... } DESCRIPTION
This module handles creating color objects used by Imager. The idea is that in the future this module will be able to handle color space calculations as well. An Imager color consists of up to four components, each in the range 0 to 255. Unfortunately the meaning of the components can change depending on the type of image you're dealing with: o for 3 or 4 channel images the color components are red, green, blue, alpha. o for 1 or 2 channel images the color components are gray, alpha, with the other two components ignored. An alpha value of zero is fully transparent, an alpha value of 255 is fully opaque. METHODS
new This creates a color object to pass to functions that need a color argument. set This changes an already defined color. Note that this does not affect any places where the color has been used previously. rgba() This returns the red, green, blue and alpha channels of the color the object contains. info Calling info merely dumps the relevant color to the log. equals(other=>$other_color) equals(other=>$other_color, ignore_alpha=>1) Compares $self and color $other_color returning true if the color components are the same. Compares all four channels unless "ignore_alpha" is set. If "ignore_alpha" is set only the first three channels are compared. You can specify colors in several different ways, you can just supply simple values: o simple numeric parameters - if you supply 3 or 4 numeric arguments, you get a color made up of those RGB (and possibly A) components. o a six hex digit web color, either "RRGGBB" or "#RRGGBB" o an eight hex digit web color, either "RRGGBBAA" or "#RRGGBBAA". o a 3 hex digit web color, "#RGB" - a value of F becomes 255. o a color name, from whichever of the gimp "Named_Colors" file or X "rgb.txt" is found first. The same as using the "name" keyword. You can supply named parameters: o 'red', 'green' and 'blue', optionally shortened to 'r', 'g' and 'b'. The color components in the range 0 to 255. # all of the following are equivalent my $c1 = Imager::Color->new(red=>100, blue=>255, green=>0); my $c2 = Imager::Color->new(r=>100, b=>255, g=>0); my $c3 = Imager::Color->new(r=>100, blue=>255, g=>0); o "hue", "saturation" and "value", optionally shortened to "h", "s" and "v", to specify a HSV color. 0 <= hue < 360, 0 <= s <= 1 and 0 <= v <= 1. # the same as RGB(127,255,127) my $c1 = Imager::Color->new(hue=>120, v=>1, s=>0.5); my $c1 = Imager::Color->new(hue=>120, value=>1, saturation=>0.5); o "web", which can specify a 6 or 3 hex digit web color, in any of the forms "#RRGGBB", "#RGB", "RRGGBB" or "RGB". my $c1 = Imager::Color->new(web=>'#FFC0C0'); # pale red o "gray" or "grey" which specifies a single channel, from 0 to 255. # exactly the same my $c1 = Imager::Color->new(gray=>128); my $c1 = Imager::Color->new(grey=>128); o "rgb" which takes a 3 member arrayref, containing each of the red, green and blue values. # the same my $c1 = Imager::Color->new(rgb=>[255, 100, 0]); my $c1 = Imager::Color->new(r=>255, g=>100, b=>0); o "hsv" which takes a 3 member arrayref, containing each of hue, saturation and value. # the same my $c1 = Imager::Color->new(hsv=>[120, 0.5, 1]); my $c1 = Imager::Color->new(hue=>120, v=>1, s=>0.5); o "gimp" which specifies a color from a GIMP palette file. You can specify the file name of the palette file with the 'palette' parameter, or let Imager::Color look in various places, typically "$HOME/gimp-1.x/palettes/Named_Colors" with and without the version number, and in "/usr/share/gimp/palettes/". The palette file must have color names. my $c1 = Imager::Color->new(gimp=>'snow'); my $c1 = Imager::Color->new(gimp=>'snow', palette=>'testimg/test_gimp_pal); o "xname" which specifies a color from an X11 "rgb.txt" file. You can specify the file name of the "rgb.txt" file with the "palette" parameter, or let Imager::Color look in various places, typically "/usr/lib/X11/rgb.txt". my $c1 = Imager::Color->new(xname=>'blue') # usually RGB(0, 0, 255) o "builtin" which specifies a color from the built-in color table in Imager::Color::Table. The colors in this module are the same as the default X11 "rgb.txt" file. my $c1 = Imager::Color->new(builtin=>'black') # always RGB(0, 0, 0) o "name" which specifies a name from either a GIMP palette, an X "rgb.txt" file or the built-in color table, whichever is found first. o 'channel0', 'channel1', etc, each of which specifies a single channel. These can be abbreviated to 'c0', 'c1' etc. o 'channels' which takes an arrayref of the channel values. Optionally you can add an alpha channel to a color with the 'alpha' or 'a' parameter. These color specifications can be used for both constructing new colors with the new() method and modifying existing colors with the set() method. METHODS
hsv() my($h, $s, $v, $alpha) = $color->hsv(); Returns the color as a Hue/Saturation/Value/Alpha tuple. AUTHOR
Arnar M. Hrafnkelsson, addi@umich.edu And a great deal of help from others - see the "README" for a complete list. SEE ALSO
Imager(3), Imager::Color http://imager.perl.org/ perl v5.14.2 2011-06-06 Imager::Color(3pm)
All times are GMT -4. The time now is 05:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy