The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing global variable to a function which is called by another function sars Shell Programming and Scripting 4 06-30-2008 08:39 AM
awk, join or sed jkl_jkl Shell Programming and Scripting 1 04-15-2008 02:55 AM
Join jazz8146 UNIX for Dummies Questions & Answers 5 01-29-2008 08:42 AM
join (pls help on join command) summer_cherry Shell Programming and Scripting 1 12-31-2007 02:19 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-06-2002
Registered User
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
join function and -o and -a

I'm completing a join where I specify the outfile format....such as:

Code:
join -t \| -j1 1 -j2 1 -o 1.1 1.2 1.3 2.4 1.5 1.6 1.7 $OUTFILE TMP_INFILE > NEW_OUTFILE
Now this works great. Now what I also want is to include any unmatched rows from the first file...and I use the -a flag for this.

What I get however is a null value in the field that is specifed to come from the second file for matches. You'll see in the -o I have 1.1 1.2 .....and 2.4 - so I want the fourth field to come from the second file - but obviously only when there is a match.

I'm getting no return in the 4th column now - it seems to just be going to the 2nd file to find this field even for the unmatched records....

How can I make the -a just insert the whole record when there is no match - and ignore the -o?

I realise that there are hack ways of doing this with sed and cut and others - but I want to understand joins as I'm just starting to use them.
__________________
Pete
Forum Sponsor
  #2  
Old 08-08-2002
Registered User
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
I haven't had much love on this issue....but I have a work around - if anyone is interested.

Well I have figured out one solution....but am still curious why the join function should work this way. Would seem to be a flaw?

I got around this by using the same field reference in both files then piping this through awk, and where 2.4 was not valid using 1.4 - or when 2.4 was valid using that i.e.

join -t\| -j1 1 -j2 1 -a 1 -o 1.1 1.2 1.3 1.4 2.4 1.5 1.6 1.7 $OUTFILE TMP_INFILE |
awk -F\| '{
if ($5 ~ /^[0-9][0-9][0-9][0-9]$/) {
x = $5
} else {
x = $4
}

printf("%s|%s|%s|%s|%s|%s|%s\n", $1, $2, $3, x, $6, $7, $8);
}' > replaced
__________________
Pete
Google The UNIX and Linux Forums
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0