The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Join Command Help jerome Sukumar Shell Programming and Scripting 0 01-24-2007 11:08 PM
Using Join Command Supial Shell Programming and Scripting 4 08-08-2005 10:12 PM
join command penfold Shell Programming and Scripting 22 02-22-2005 04:37 AM
Join command unisam UNIX for Dummies Questions & Answers 4 07-28-2004 03:59 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-31-2007
Registered User
 

Join Date: Jun 2007
Posts: 355
join (pls help on join command)

Hi,

I am a new learner of join command. Some result really make me confused.
Please kindly help me.

input:
Code:
file1:
LEO oracle engineer 210375
P.Jones Office Runner ID897
L.Clip Personl Chief ID982
S.Round UNIX admin ID6

file2:
Dept2C ID897 6 years
Dept5Z ID982 1 year
Dept3S ID6 2 years
GEDA 210375 1 year
What i exactly want is:
Code:
ID897 P.Jones Office Runner Dept2C 6 years
ID982 L.Clip Personl Chief Dept5Z 1 year
ID6 S.Round UNIX admin Dept3S 2 years
210375 LEO oracle engineer GEDA 1 year
Follow is the code and result according to my example. Could anybody explain why the result is not correct. It seems my soaris can only output first two lines(since if i split the input file to four groups, and each group contain only one line, it works ok.)

Thanks in advanced!

Code:
code1: join -j1 4 -j2 2 file1 file2
result1:
ID897 P.Jones Office Runner Dept2C 6 years
ID982 L.Clip Personl Chief Dept5Z 1 year

code2:join -a1 -j1 4 -j2 2 file1 file2
reuslt2:
210375 LEO oracle engineer
ID897 P.Jones Office Runner Dept2C 6 years
ID982 L.Clip Personl Chief Dept5Z 1 year

code3:
join -a2 -j1 4 -j2 2 file1 file2
reustl3:
ID897 P.Jones Office Runner Dept2C 6 years
ID982 L.Clip Personl Chief Dept5Z 1 year
ID6 Dept3S 2 years
210375 GEDA 1 year
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-31-2007
jaduks's Avatar
Registered User
 

Join Date: Aug 2007
Location: Assam,India
Posts: 141
A quick fix :-) Hope this works

$ cat fil1
LEO oracle engineer 210375
P.Jones Office Runner ID897
L.Clip Personl Chief ID982
S.Round UNIX admin ID6

$ cat fil2
Dept2C ID897 6 years
Dept5Z ID982 1 year
Dept3S ID6 2 years
GEDA 210375 1 year

$ sort +3 -4 fil1 > fil1.tmp
$ sort +1 -2 fil2 > fil2.tmp

$ join -1 4 -2 2 fil1.tmp fil2.tmp
210375 LEO oracle engineer GEDA 1 year
ID6 S.Round UNIX admin Dept3S 2 years
ID897 P.Jones Office Runner Dept2C 6 years
ID982 L.Clip Personl Chief Dept5Z 1 year
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:28 PM.


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

Content Relevant URLs by vBSEO 3.2.0