473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Joining(merging) two files.

sumittyagi
202 Expert 100+
Hi All,

I am stuck with one tricky situation here.

The situation is as follows:-
I have two files, both files have two columns - space seperated key value pairs.

Now say files are f1 and f2.
and columns in f1 are f1c1, f1c2; and columns in f2 are f2c1 and f2c2.

f2c1 is a subset of f1c1 (say keys).
f1c2 and f2c2 are different (say values).

Now I want to merge f1 and f2 into a file f3, so that f3 has three columns (space seperated):-
f1c1, f1c2, f2c2. (in DB terms I want to perform a left outer join).

I have no clue how to perform that. Can anybody assist me in this.

Thanks in advance for your valuable inputs.

Best Regards,
Sumit
Sep 20 '09 #1
3 4773
sumittyagi
202 Expert 100+
I am half way through:-

I tried to use join command, but it seems to compare in an ambiguous manner:-

Below is the sample output:-
file1 is:-
file1:-
1 51
2 52
3 53
4 54
5 55
6 56
7 57
8 58
9 59
10 60
11 61
12 62
13 63
15 65
16 66
17 67
18 68
20 70
22 72
24 74
...
...
100 150
file2 is:-
file 2:-
1 2605
2 1486
3 2783
4 2714
5 26892
6 2645
7 2838
8 84
9 143
10 26962
11 27068
12 27168
13 27250
15 27330
16 27425
17 27507
18 27594
20 27693
22 27785
24 27878
...
...
100 3291
join command gives output for one digit matches only for the key match column as shown below:-
Expand|Select|Wrap|Line Numbers
  1. join -j1 1 -j2 1 -o 0,1.2,2.2 -t " " file1 file2
  2. 1 51 2605
  3. 2 52 1486
  4. 3 53 2783
  5. 4 54 2714
  6. 5 55 26892
  7. 6 56 2645
  8. 7 57 2838
  9. 8 58 84
  10. 9 59 143
Note:- I don't want to use for loops to perform this task because if there are 100 rows in the files then there will be approx. 100X100 iterations, that will severely hamper the performance of the script.
Sep 20 '09 #2
sumittyagi
202 Expert 100+
I think arrays will solve my problem...

Any other suggestions?
Sep 22 '09 #3
sumittyagi
202 Expert 100+
Yes, arrays solved it out. it took 3 full iterations (if there are 100 elements then 3X100=300 iterations => two for assignment and one for display).

Any other improvement suggestion will be appreciated.
Sep 23 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Edgar Vigdal | last post by:
Hi! I'm trying to make a script that will download first one file (the main file) and then download some extra data in the same stream. 1=file 1 2=file 2 ...
0
by: Mark | last post by:
Hi all, I have 2 files containing Id numbers and surnames (these files essentially contain the same data) I want to select distinct() and join on id number to return a recordset containing every...
5
by: Hugh Janus | last post by:
Hi group, I have an app that streams files over the network. What I want to be able to do now is select a folder and stream the entire contents of that folder over the network. I could simply...
2
by: amy | last post by:
Hi, all: i am a new end user of access, now I have many excel files need to import to One table in access (combine all excel files into one table in excel). In excel files, some columns will have...
7
by: JoNo216 | last post by:
hey guys, I'm a little new when it comes to the ASP environment, and I need a little help... Does anyone know how to combine two separate datatables, and get them to display one after the other...
1
by: shortyzms | last post by:
Hello Experts, Let's say I have 4 lines in a child table that point to a line in a parent table. Right now I'm INNER JOINing them on the parent table's primary key, and it's giving me 4 records...
6
by: Carter | last post by:
This is probably somewhat of a beginners question but I am unfamiliar with alot of aspects of C++. What is the correct way to append multiple STL containers together in constant time. Obviously you...
5
by: Albert-jan Roskam | last post by:
Hi, I wrote the program below to merge all xls files in a given directory into one multisheet xls file. It uses xlwt and xlrd. The xls files I use for input are generated by Spss. When I open and...
0
by: Albert-jan Roskam | last post by:
Hi John, Thanks! Using a higher xlrd version did the trick! Regarding your other remarks: -yep, input files with multiple sheets don't work yet. I kinda repressed that ;-) Spss outputs only...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.