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 and shell scripting languages here.

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 unisam UNIX for Dummies Questions & Answers 4 07-28-2004 07:59 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 02-21-2005
penfold penfold is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 48
join command

Hi,

I'm using the join command and it appears to discard certain fields. Here are the two files i'm comparing:

File1:
1 a
2 b
3 c
4 d
99 f
101 g
999 i
200 j

File 2:
1 e
2 f
3 g
4 h
99 h
101 i
999 j
200 k

> join 1 2
results in:

1 a e
2 b f
3 c g
4 d h
99 f h
999 i j

So 101 and 200 have been ignored....any ideas why?

Cheers
  #2 (permalink)  
Old 02-21-2005
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
The files must be sorted first.

From the join manual page....
Quote:
file1 and file2 must be sorted in increasing ASCII-collating sequence
on the fields on which they are to be joined, usually the first in
each line.
So....
Code:
$ sort 1 > 1.sorted
$ sort 2 > 2.sorted
$ join 1.sorted 2.sorted
1 a  e
101 g  i
2 b  f
200 j  k
3 c  g
4 d  h
99 f  h
999 i  j
Cheers
ZB
  #3 (permalink)  
Old 02-21-2005
penfold penfold is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 48
adding a tab to the output

Thanks - you were right it was because it wasn't correctly sorted.

Does anyone know how to add a tab to the output of the join command i.e. the fields that are added should be seperated from the rest with a tab?


e.g.

1 g </tab> h
3 g </tab> i

Cheers
  #4 (permalink)  
Old 02-21-2005
codpilot codpilot is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 10
more join problems

Well here's my join issue

I have a file in the following format:
id/name/salary/position

and a file in the following format
number,amount,id

if I use sed to replace the different separators with a ":" and try to join them - the join fails to match on id.

However if I type the files in with the : separator already in place - the join works fine.

Sadly I am the instructor - and tested the script with my pre-made files (with the ":") but assigned the work with different separators to make the class use sed to convert them.

Both files are sorted (ascii) and other than the separators are identical. Anyone have a clue as to why this would happen?
  #5 (permalink)  
Old 02-21-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
looking at 'man join':
Quote:
-1n uses the nth field of file1 as the join key field.

-2n uses the nth field of file2 as the join key field.
  #6 (permalink)  
Old 02-21-2005
codpilot codpilot is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 10
I did that:

join -t: -1 3 -2 1 file1 file2

and if I hand type the files in - no problem. If however I use the original files with the differing separators, use sed to convert them to a ":" then the join fails. Same command, same file (except the separators in one have been manually entered, and the second time they were converted) different results

sigh such a pita
  #7 (permalink)  
Old 02-21-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
could you post a sample script AND sample input files?
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 05:39 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