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
join (pls help on join command) summer_cherry Shell Programming and Scripting 1 12-31-2007 05:19 AM
Join Command Help jerome Sukumar Shell Programming and Scripting 0 01-25-2007 03:08 AM
Using Join Command Supial Shell Programming and Scripting 4 08-09-2005 02:12 AM
join command penfold Shell Programming and Scripting 22 02-22-2005 08:37 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-28-2004
unisam unisam is offline
Registered User
  
 

Join Date: Mar 2004
Posts: 6
Unhappy Join command

Hi,

I am trying to join 2 files..viz

f1:
12~a1
13~a2
112~a3
1112~a4

f2:
12~fa2
13~fa2
112~fa3
1112~fa4


while I join..I just get 2 o/p..
12~a1~fa2
13~a2~fa2

while the rest doesnt appear:-(

Can any1 help me in this plss?

Thanx
Sam
  #2 (permalink)  
Old 07-28-2004
JoBa JoBa is offline
Registered User
  
 

Join Date: Sep 2002
Location: The Netherlands
Posts: 16
You can use -o option to specify the fields you want to see in the output.

join -o 1.1 1.2 2.1 2.2 file1 file2

will show the first two fields for both files in one line.

Try man join.
  #3 (permalink)  
Old 07-28-2004
JoBa JoBa is offline
Registered User
  
 

Join Date: Sep 2002
Location: The Netherlands
Posts: 16
You can also try the paste command.

paste file1 file2
  #4 (permalink)  
Old 07-28-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
The join command requires that the files be sorted in lexical sequence. Your files are sorted by numerical sequence.

$ cat f1
12~a1
13~a2
112~a3
1112~a4
$ cat f2
12~fa2
13~fa2
112~fa3
1112~fa4
$ join -t '~' f1 f2
12~a1~fa2
13~a2~fa2
$ sort f1 > s1
$ sort f2 > s2
$ join -t '~' s1 s2
1112~a4~fa4
112~a3~fa3
12~a1~fa2
13~a2~fa2
  #5 (permalink)  
Old 07-28-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
I've just realised that you don't have to sort the files if you use awk...

$ awk 'BEGIN{FS=OFS="~"}FNR==NR{a[$1]=$2}FNR!=NR{print $1,a[$1],$2}' f1 f2
12~a1~fa2
13~a2~fa2
112~a3~fa3
1112~a4~fa4
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0