The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 two files koti_rama Shell Programming and Scripting 5 08-05-2008 04:20 AM
Join two files koti_rama Shell Programming and Scripting 4 06-10-2008 06:15 AM
Join columns from 2 files osramos Shell Programming and Scripting 2 11-14-2007 05:25 AM
how to join files jxh461 UNIX for Dummies Questions & Answers 5 08-23-2007 07:11 AM
join files mohan705 Shell Programming and Scripting 3 03-15-2007 06:51 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-17-2006
choppas choppas is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 5
Join Files

Hi Gurus,
I have to join two flat files based on two key field columns. I concatenated two key fields and i tried the join command. It is working
fine. But, without using temporary files can't i use like this:

join -t ':' `awk -F ":" '{ printf("%s%s:%s\n", $1,$2, $0) }' file1` `awk -F ":" '{ printf("%s%s:%s\n", $1,$2, $0) }' file2`

My each file is having the size nearly 2 GB. Similary i need to run 27 jobs parellely (scripts which are using join).
So i need to join 54 files approximately. If i use temporary files 54 * 2 = 108 GB space needs to be utilized more.

Without using temporary files is there any other approach to proceed?

Thanks in advance
Srinivas Choppa
  #2 (permalink)  
Old 10-17-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
try:
Code:
awk '
    FILENAME=="file1" {
        Keys[$1 $2]=$0
    }
    FILENAME=="file2" {
    	if (Keys[$1 $2]>" "){
         printf("%s ", Keys[$1 $2]);
         for(i=3;i<=NF;i++) printf("%s ",$i);
         printf("\n");
        }
    }
' file1 file2
This produces $0 (whole record) from file1 joined with alll of the record after they key from file2.
  #3 (permalink)  
Old 10-18-2006
choppas choppas is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 5
Hi Jim,

Thank you for the reply.

But, i am unable to use the array contents (Key[$1 $2]) created in file1 block in file2 block. Means everytime it is returning NULL value in File2 block.

I am very much new to AWK programming. Can you please explain?

Thanks in advance,
Srinivas Choppa
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:24 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