Sponsored Content
Top Forums Shell Programming and Scripting Match Columns in one file and extract columns from another file Post 303002057 by RudiC on Thursday 17th of August 2017 02:55:17 AM
Old 08-17-2017
While rdrtx1's proposal works fine for the samples given, it doesn't for the duplicates mentioned as the samples don't have any. Nor is the request for <TAB> field separators in the result fulfilled. Try

Code:
awk '

                {IX1 = $1 OFS $2 OFS $3 OFS $4
                 IX2 = $1 OFS $3 OFS $5 OFS $6
                 $1 = $1
                }

FNR==1          {printf $0 ((c++) ? "\n" : "\t")
                }

NR==FNR         {a[IX1] = $0
                 next
                }

a[IX2]          {print a[IX2] "\t" $0
                }
' OFS="\t" file[12]

This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to extract columns from a text file

Hi, In ksh, I have a file with similar rows as follows: Department = 1234 G/L Asset Acct No = 12.0000. 2/29/2008 Department = 1234 G/L Asset Acct No = 13.0000. 3/29/2008. I want to create a new text file that contains only the numbers and date: 1234 12.0000. 2/29/2008 1234 13.0000. ... (16 Replies)
Discussion started by: ihot
16 Replies

2. Shell Programming and Scripting

Help, need to extract columns from file

I have huge fixed width, text file in unix box and I need to extract columns found between the width 105 and 200 and output it to a new file. Can anyone tell me how to extract it? Thanks for your help. (1 Reply)
Discussion started by: kiran2k
1 Replies

3. Shell Programming and Scripting

use of format file to extract columns from a source file

hi experts lets say my format file is B B ========= column no,name,type,length 1,ee,N,12 3,hj,N.4 4,kl,N,5 source file ======== d e f g h i 5 8 9 7 6 5 1 3 4 5 6 6 (2 Replies)
Discussion started by: subhendu81
2 Replies

4. Shell Programming and Scripting

Extract Columns from file

Hi All, Could you please help me with following: I have to parse a .csv file. For example: If the csv file contains 3 columns, then i have to print the column names. The field separator is (comma). example.csv (contains 2 lines as follows) This is,a test file, for validation... (2 Replies)
Discussion started by: vfrg
2 Replies

5. Shell Programming and Scripting

Get columns from another file for match in col 2 in 1st file

Hi, My first file has 592155 9 rs16916098 1 592156 19 rs7249604 1 592157 4 rs885156 1 592158 5 rs350067 12nd file has 9 rs16916098 0 113228129 2 4 19 rs7249604 0 58709070 4 2 2 rs17042833 0 113558750 4 2... (2 Replies)
Discussion started by: genehunter
2 Replies

6. Shell Programming and Scripting

Match and print columns in second file

Hi All, I have to match each row in file 1 with 1st row in file 2 and print the corresponding column from file2. I am trying to use an awk script to do this. For example cat File1 X1 X3 X4 cat File2 ID X1 X2 X3 X4 A 1 6 2 1 B 2 7 3 3 C 3 8 4 1 D 4 9 1 1 (3 Replies)
Discussion started by: newpro
3 Replies

7. Shell Programming and Scripting

Evaluate 2 columns, add sum IF two columns match on two rows

Hi all, I know this sounds suspiciously like a homework course; but, it is not. My goal is to take a file, and match my "ID" column to the "Date" column, if those conditions are true, add the total number of minutes worked and place it in this file, while not printing the original rows that I... (6 Replies)
Discussion started by: mtucker6784
6 Replies

8. Shell Programming and Scripting

Request: How to Parse dynamic SQL query to pad extra columns to match the fixed number of columns

Hello All, I have a requirement in which i will be given a sql query as input in a file with dynamic number of columns. For example some times i will get 5 columns, some times 8 columns etc up to 20 columns. So my requirement is to generate a output query which will have 20 columns all the... (7 Replies)
Discussion started by: vikas_trl
7 Replies

9. Shell Programming and Scripting

Match pattern from file 1 with any/all columns in file 2

Hi, I have been looking everywhere for an example so I can try and do this myself but I am having difficulty. I have 2 large files of different sizes and if the pattern in the 3rd column in file 1 is in "any" column in file 2 I want to print all of the line in file 1 and append that line with the... (5 Replies)
Discussion started by: kieranfoley
5 Replies

10. Shell Programming and Scripting

Extract columns into seperate file

I have a comma delimited file as per the one below and I am currently extracting the values in 2 columns (COL1 & COL6) to produce a smaller trimmed down version of the file which only contains the columns we need; COL1,COL2,COL3,COL4,COL5,COL6,COL7,COL8,COL9... (1 Reply)
Discussion started by: Ads89
1 Replies
Mojolicious::Routes::Match(3pm) 			User Contributed Perl Documentation			   Mojolicious::Routes::Match(3pm)

NAME
Mojolicious::Routes::Match - Routes visitor SYNOPSIS
use Mojolicious::Routes; use Mojolicious::Routes::Match; # Routes my $r = Mojolicious::Routes->new; $r->get('/foo')->to(action => 'foo'); $r->put('/bar')->to(action => 'bar'); # Match my $m = Mojolicious::Routes::Match->new(PUT => '/bar'); $m->match($r); say $m->captures->{action}; DESCRIPTION
Mojolicious::Routes::Match is a visitor for Mojolicious::Routes structures. ATTRIBUTES
Mojolicious::Routes::Match implements the following attributes. "captures" my $captures = $m->captures; $m = $m->captures({foo => 'bar'}); Captured parameters. "endpoint" my $endpoint = $m->endpoint; $m = $m->endpoint(Mojolicious::Routes->new); The routes endpoint that actually matched. "root" my $root = $m->root; $m = $m->root($routes); The root of the routes tree. "stack" my $stack = $m->stack; $m = $m->stack([{foo => 'bar'}]); Captured parameters with nesting history. METHODS
Mojolicious::Routes::Match inherits all methods from Mojo::Base and implements the following ones. "new" my $m = Mojolicious::Routes::Match->new(GET => '/foo'); my $m = Mojolicious::Routes::Match->new(GET => '/foo', $ws); Construct a new match object. "match" $m->match(Mojolicious::Routes->new, Mojolicious::Controller->new); Match against a routes tree. "path_for" my $path = $m->path_for; my $path = $m->path_for(foo => 'bar'); my $path = $m->path_for({foo => 'bar'}); my $path = $m->path_for('named'); my $path = $m->path_for('named', foo => 'bar'); my $path = $m->path_for('named', {foo => 'bar'}); my ($path, $ws) = $m->path_for; my ($path, $ws) = $m->path_for(foo => 'bar'); my ($path, $ws) = $m->path_for({foo => 'bar'}); my ($path, $ws) = $m->path_for('named'); my ($path, $ws) = $m->path_for('named', foo => 'bar'); my ($path, $ws) = $m->path_for('named', {foo => 'bar'}); Render matching route with parameters into path. SEE ALSO
Mojolicious, Mojolicious::Guides, <http://mojolicio.us>. perl v5.14.2 2012-09-05 Mojolicious::Routes::Match(3pm)
All times are GMT -4. The time now is 08:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy