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
Trouble with awk RichieFondel Shell Programming and Scripting 1 01-17-2008 07:30 AM
join (pls help on join command) summer_cherry Shell Programming and Scripting 1 12-31-2007 05:19 AM
The trouble about SU ... nulnul7 UNIX for Dummies Questions & Answers 4 10-05-2005 12:39 PM
The trouble with... zazzybob What's on Your Mind? 6 01-18-2005 06:01 AM
trouble awk UNIX Desktop for Dummies Questions & Answers 1 11-22-2002 10:51 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 09-19-2008
stonemonolith stonemonolith is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 19
trouble with join

Hello

I've got two files; each has 6 records each. I want to join the files so I can compare the reserved space of tables on one server with the same tables on another server.

I tried the join command but, it 's not joining all of the rows. I know I'm missing something simple but, I can't see it.

Here is file1
fctenv01 CER_MCZT_ZIP_TRANS 79877 11776 10868 776 132
fctenv01 CMC_CECE_CRITERIA 150911 17692 17512 112 68
fctenv01 CMC_EBCL_EOB_DATA 106651 3168 3004 24 140
rptenv01 CER_MCZT_ZIP_TRANS 79877 11779 10877 766 142
rptenv01 CMC_CECE_CRITERIA 150923 18692 17522 122 78
rptenv01 CMC_EBCL_EOB_DATA 106652 3768 3114 44 240

Here is file2
fctenv01 CER_MCZT_ZIP_TRANS 80225 12320 10700 1496 124
fctenv01 CMC_CECE_CRITERIA 150930 17692 17512 112 68
fctenv01 CMC_EBCL_EOB_DATA 106470 3136 3000 28 108
rptenv01 CER_MCZT_ZIP_TRANS 80229 12439 12475 1596 224
rptenv01 CMC_CECE_CRITERIA 151230 18792 18722 212 78
rptenv01 CMC_EBCL_EOB_DATA 116570 3276 3123 78 128

Here is the join statement I am using
join -1 2 -2 2 $file1 $file2 | awk '{tot=$3-$4};{print $2,$1,$3,$4,tot}' | sort -1 +4rn

And here is the output
fctenv01 CMC_CECE_CRITERIA 150911 17692 133219
fctenv01 CMC_EBCL_EOB_DATA 106651 3168 103483
fctenv01 CER_MCZT_ZIP_TRANS 79877 11776 68101
rptenv01 CMC_EBCL_EOB_DATA 106652 3768 102884
rptenv01 CMC_EBCL_EOB_DATA 106652 3768 102884

The first two rptenv01 tables are missing on the output and the last rptenv01 table is listed twice.

Here is the output I would like the join to give me
fctenv01 CMC_CECE_CRITERIA 150911 17692 133219
fctenv01 CMC_EBCL_EOB_DATA 106651 3168 103483
fctenv01 CER_MCZT_ZIP_TRANS 79877 11776 68101
rptenv01 CMC_CECE_CRITERIA 150923 18692 132231
rptenv01 CMC_EBCL_EOB_DATA 106652 3768 102884
rptenv01 CER_MCZT_ZIP_TRANS 79877 11779 68098

What am I missing? Any help would be greatly appreciated!

tia
  #2 (permalink)  
Old 09-19-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,418
will this do??
Quote:
while read line1
do
while read line2
do
if [ "`echo "$line2"|awk '{print $1$2}'`" == "`echo "$line1"|awk '{print $1$2}'`" ]
then
echo "$line1"|awk '{tot=$3-$4};{print $1,$2,$3,$4,tot}'| sort -1 +4rn
fi
done < a
done < z
  #3 (permalink)  
Old 09-19-2008
stonemonolith stonemonolith is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 19
Thanks - it works fine!
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 08:15 AM.


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