UNIX outer join


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers UNIX outer join
# 8  
Old 10-07-2013
Thank you.

I'm working on a HP-UX system..The man page of join says this at the end.
Code:
STANDARDS CONFORMANCE
      join: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2

and like you said, maybe this POSIX.2 is older than 1997

I wrote this join function with awk and seems to be working. Once confirmed, i will paste it here..

---------- Post updated at 01:55 PM ---------- Previous update was at 01:30 PM ----------

Found a small work around with awk:

The input files are more like this now: (in the first file, I cannot always know how many fields are present..and in second file,only the last field matters. ***So,Mo,Tu are just example field names )
Code:
cat xxx yyy
item,So,Mo,Tu
aaa,1,1,1
bbb,1,1,4
ccc,1,1,0
ddd,1,1,1
 
item,We
aaa,1
bbb,0
eee,1
fff,2

Code:
awk -F\, '{OFS=","} 
NR==FNR { A[$1]=$0 ; b[$1]="0" ; fields1=NF-1; next }
($1) in A { b[$1]=$NF } 
!(($1) in A ){
A[$1]=$1
filler="0"
for (i = 1; i < fields1; i++) { filler=filler",0" }
b[$1]=filler","$NF
}
END { for (i in A) print A[i],b[i]}' xxx yyy |sort

output:
Code:
aaa,1,1,1,1
bbb,1,1,4,0
ccc,1,1,0,0
ddd,1,1,1,0
eee,0,0,0,1
fff,0,0,0,2
item,So,Mo,Tu,We

now,i will deal with the header

Does it look ok?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
Login or Register to Ask a Question