Sponsored Content
Full Discussion: UNIX outer join
Top Forums UNIX for Dummies Questions & Answers UNIX outer join Post 302859153 by Yoda on Wednesday 2nd of October 2013 12:47:30 PM
Old 10-02-2013
An approach using awk (not simple as join Smilie):
Code:
awk -F, '
        NR == FNR {
                        idx = idx < NF ? NF : idx
                        if ( FNR == 1 )
                        {
                                for ( i = 1; i <= NF; i++ )
                                        H1[i] = $i
                        }
                        else
                        {
                                if ( !(K[$1]) )
                                {
                                        T[++j] = $1
                                        K[$1] = $1
                                }
                                for ( i = 2; i <= NF; i++ )
                                        V[$1,H1[i]] = $i
                        }
                        next
        }
        {
                        idx = idx < NF ? NF : idx
                        if ( FNR == 1 )
                        {
                                for ( i = 1; i <= NF; i++ )
                                        H2[i] = $i
                        }
                        else
                        {
                                if ( !(K[$1]) )
                                {
                                        T[++j] = $1
                                        K[$1] = $1
                                }
                                for ( i = 2; i <= NF; i++ )
                                        V[$1,H2[i]] = $i
                        }
        }
        END {

                        for ( i = 1; i <= idx; i++ )
                        {
                                if ( !R[H1[i]] && H1[i] )
                                {
                                        H[++c] = H1[i]
                                        R[H1[i]] = H1[i]
                                }
                        }
                        for ( i = 1; i <= idx; i++ )
                        {
                                if ( !R[H2[i]] && H2[i] )
                                {
                                        H[++c] = H2[i]
                                        R[H2[i]] = H2[i]
                                }
                        }
                        for ( i = 1; i <= c; i++ )
                                h = h ? h OFS H[i] : H[i]
                        print h
                        for ( s = 1; s <= j; s++ )
                        {
                                for ( i = 1; i <= c; i++ )
                                {
                                        t = V[T[s],H[i]] ? V[T[s],H[i]] : "0"
                                        f = f ? f OFS t : T[s]
                                }
                                print f
                                f = ""
                        }

        }
' OFS=, xxx yyy

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

unix join !

just wandering if anyone knows what kind of algorithm unix join command is using to join 2 files. Thanks! (2 Replies)
Discussion started by: strike
2 Replies

2. Programming

Oracle: fixing an outer join on subquery...

I have a stored procedure that is failing. The current query behind it is: SELECT DISTINCT <many, many values> FROM table1 LEFT OUTER JOIN table2 ON (table2.key = (select max (table2.key) from table2 where table2.key = table1.key) or ... (0 Replies)
Discussion started by: Elric of Grans
0 Replies

3. Programming

sql,multiple join,outer join issue

example sql: select a.a1,b.b1,c.c1,d.d1,e.e1 from a left outer join b on a.x=b.x left outer join c on b.y=c.y left outer join d on d.z=a.z inner join a.t=e.t I know how single outer or inner join works in sql. But I don't really understand when there are multiple of them. can... (0 Replies)
Discussion started by: robbiezr
0 Replies

4. Shell Programming and Scripting

How can i join three lines into one in unix?

Hi all, I am trying to merge three lines into one in my unix text file. My text file sis omething like this. xxxxxxxxx yyyyyyyyyyy zzz aaaaaaaaa bbbbbb ccccc Expected out put is xxxxxxxxx yyyyyyyyyyy zzz aaaaaaaaa bbbbbb ccccc I tried with awk as shown below. (23 Replies)
Discussion started by: rdhanek
23 Replies

5. Programming

OUTER join?

Hi, I have a code where it traverses through each record froma table and creates records in another table. I use FOREACH cursor to do this, i'm using another cursor inside the FOREACH to fetch the details of other table. Please suggest me which would be more efficient, as this will run against... (2 Replies)
Discussion started by: dvah
2 Replies

6. Shell Programming and Scripting

Unix Join

Hi, I am trying to join two simple files but unable to do so properly. File R1 : 100 101 102 105 . . 1000 10001 File R2 100|x1 102|x2 1000|a1 10001|a2 and when i do (4 Replies)
Discussion started by: wanderingmind16
4 Replies

7. UNIX for Dummies Questions & Answers

how to join all lines in afile in unix

Hi, I have a unix file which has many lines, i need to join all the lines to single line. Eg: myfile.txt contains: a 123 45fg try and i need the output as : a 123 45fg try Please help me on this. Thanks! (2 Replies)
Discussion started by: RP09
2 Replies

8. Shell Programming and Scripting

Break the outer loop

Hi I'm comparing same files names which are in different folders . The first for loop for the files in DAY1 folder and the second for loop for the files in DAY2 folder . the first IF condition is for checking whether the file names are equal the second If condtion is for checking the... (4 Replies)
Discussion started by: smile689
4 Replies

9. Shell Programming and Scripting

How to join two different file in UNIX?

Hello folks I have 2 files which are like this: file (a): id phenotype 100 1.2 200 -0.5 300 3.1 file (b) id genotype 100 0 1 2 ...... 200 1 1 1...... 300 2 0 0 ....... I should mention in file (a) I have 2... (3 Replies)
Discussion started by: sajmar
3 Replies

10. Shell Programming and Scripting

UNIX Join not working as expected

Hello All, I'm working on a Shell script to join data from two files using Join command but not able to get the desired output as its throwing me an error: I have sorted the two files on the Column 1 numerically which is used as Join clause File 1: 1,ABC,GGG,20160401 2,XYZ,KKK,20160401... (2 Replies)
Discussion started by: venkat_reddy
2 Replies
SSL_CTX_get_ex_new_index(3)					      OpenSSL					       SSL_CTX_get_ex_new_index(3)

NAME
SSL_CTX_get_ex_new_index, SSL_CTX_set_ex_data, SSL_CTX_get_ex_data - internal application specific data functions SYNOPSIS
#include <openssl/ssl.h> int SSL_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); int SSL_CTX_set_ex_data(SSL_CTX *ctx, int idx, void *arg); void *SSL_CTX_get_ex_data(SSL_CTX *ctx, int idx); typedef int new_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad, int idx, long argl, void *argp); typedef void free_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad, int idx, long argl, void *argp); typedef int dup_func(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d, int idx, long argl, void *argp); DESCRIPTION
Several OpenSSL structures can have application specific data attached to them. These functions are used internally by OpenSSL to manipu- late application specific data attached to a specific structure. SSL_CTX_get_ex_new_index() is used to register a new index for application specific data. SSL_CTX_set_ex_data() is used to store application data at arg for idx into the ctx object. SSL_CTX_get_ex_data() is used to retrieve the information for idx from ctx. A detailed description for the *_get_ex_new_index() functionality can be found in RSA_get_ex_new_index(3). The *_get_ex_data() and *_set_ex_data() functionality is described in CRYPTO_set_ex_data(3). SEE ALSO
ssl(3), RSA_get_ex_new_index(3), CRYPTO_set_ex_data(3) 0.9.7a 2001-05-14 SSL_CTX_get_ex_new_index(3)
All times are GMT -4. The time now is 10:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy