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
Can't alter bootlist mooshkie AIX 2 01-28-2008 10:12 AM
Alter Table Shell Script ankitgupta Shell Programming and Scripting 2 10-06-2006 07:01 AM
how to alter the old file permanently using sed? mxms755 UNIX for Dummies Questions & Answers 2 04-06-2006 03:09 AM
To alter perl /bin/date output by - 5 hours Texan Shell Programming and Scripting 2 08-17-2005 09:28 AM
file not found..but file is there, also zip problem caddyjoe77 UNIX for Dummies Questions & Answers 4 04-23-2005 06:47 PM

 
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 Rating: Thread Rating: 1 votes, 4.00 average. Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 06-20-2008
manas_ranjan's Avatar
manas_ranjan manas_ranjan is offline
Registered User
  
 

Join Date: Jul 2007
Location: Amsterdam
Posts: 177
File Merging Problem

i have 3 files
a.txt , b.txt and c.txt
each files have keyfields and some column fields
e.g.
a.txt
keyfield1 keyfield2 keyfield3 col1 col2 col3
1 2 3 44 55 66
4 5 6 92 48 33
.....................etc..................
b.txt
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4
1 2 3 44 55 66 78
4 5 6 92 48 33 99
.....................etc..................
b.txt
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4 col5
7 8 9 447 255 366 678 25
4 5 6 92 48 33 97 43
1 2 3 44 55 66 78 88
.....................etc..................
key fields are the primary keys to these above files
here 1 st key is 123then
script will check a.txt's col1,col2,col3 to b.txt's col1,col2,col3 and c.txt's col1,col2,col3
for the key field 123
here all values are equal for key field 123 if not matches then script will exit for further checking telling that for key field 123 initial matches are not OK .

so it will append result.txt
as
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4 col5
1 2 3 44 55 66
then since b.txt and c.txt have some extra columns col4 and col5
so it will check col4 of b.txt with col4 of c.txt
if it matches then matching value will be there if not matching then nonmatch vales separted by comma will be there
so result.txt will be
as
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4 col5
1 2 3 44 55 66 78
here col5 is the extra column in c.txt for the same keyfield 123, so simply this will be placed as col5
so result.txt will be
as
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4 col5
1 2 3 44 55 66 78 88
similary for keyfiled 456 result.xtx will be
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4 col5
1 2 3 44 55 66 78 88
4 5 6 92 48 33 99,97 43
if any file has extra line(s) and has no matches to any files then it will simply append into the result.txt
so final result.txt will be
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4 col5
1 2 3 44 55 66 78 88
4 5 6 92 48 33 99,97 43
7 8 9 447 255 366 678 25

i am not sure, whether i expalined my situtaion prperly or not. but please let me know if it's not.
but if so, then kindly let me know how to achieve this ????

NOTE: Ther might be n number of columns..depends on the requirement . So script should accumulate such number of columns dynamaically .

Last edited by manas_ranjan; 06-20-2008 at 11:53 AM..
 

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:54 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