How to join flat files together under unix


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to join flat files together under unix
# 1  
Old 02-07-2005
Question How to join flat files together under unix

Hi,

I have 7 big flat files, each contains 24 million records which have been sorted by the first field delimitered by Ctrl B (002).

I want to join them together side by side, eg.

File A:

1^Ba^Bb
2^Bx^By
....

File B:
1^Bc^Bd
2^Bm^Bn
....

After merged, it should look like :

File C :
1^Ba^Bb^Bc^Bd
2^Bx^By^Bm^Bn
....

Can anyone tell me if I can do this under unix and how ?

I will appreciate to any advices

xlil
# 2  
Old 02-07-2005
put literally a tab in sed as 'paste' put a tab as delimiter.

Code:
paste filea fileb | sed "s/   .//"

# 3  
Old 02-07-2005
Thanks, bhargav. Smilie

Code:
www# cat filea fileb
aaa
bbb
ccc
ddd
eee
fff
www# paste filea fileb | sed "s/   .//"
aaa     ddd
bbb     eee
ccc     fff

xli, you might want to redirect to a file:

Code:
paste filea fileb | sed "s/   .//"  > filec

# 4  
Old 02-07-2005
how to join two more files....

Thanks, Neo and bhargav,

furthermore, is it possible to join more than two files at one time ?

Xli
# 5  
Old 02-07-2005
Code:
paste filea fileb filec | sed "s/   .//" > filed

# 6  
Old 02-07-2005
There is a join command. The use of cntl-B makes this hard to use from the command line. But as a shell script....

#! /usr/bin/ksh
join -t^B a b > c
exit 0

will do what was requested in the first post. See "man join" for more info.
# 7  
Old 02-07-2005
Great!. That's exactly what I want. Two more questions :

First, as all of my flat files are huge, each contains around 24 millions records. If I join them tegether in one command, is it possible running out of memory ? In other words, does the script you wrote to me consumes memory very much ?

Second, I presume that data of the flat files might conain tab, so can I use other character as delimiter eg. Ctrl B, how to define in sed command ?

I appreciate to your help.

xli
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join, merge, fill NULL the void columns of multiples files like sql "LEFT JOIN" by using awk

Hello, This post is already here but want to do this with another way Merge multiples files with multiples duplicates keys by filling "NULL" the void columns for anothers joinning files file1.csv: 1|abc 1|def 2|ghi 2|jkl 3|mno 3|pqr file2.csv: 1|123|jojo 1|NULL|bibi... (2 Replies)
Discussion started by: yjacknewton
2 Replies

2. Shell Programming and Scripting

How to join one file with multiple files in a directory in UNIX?

Dear folks Hello I have a one file called (file1) which the structure looks like this 1 gi|358484521|ref|NW_003764373.1| 1 gi|358484520|ref|NW_003764374.1| 1 gi|358484519|ref|NW_003764375.1| . . . 30 gi|368484519|ref|NW_00449375.1| In addition, I have around 300... (19 Replies)
Discussion started by: sajmar
19 Replies

3. Shell Programming and Scripting

Comparing two files in UNIX and create a new file similar to equi join

I have 2 files namely branch.txt file & RXD.txt file as below Ex:Branch.txt ========================= B1,Branchname1,city,country B2,Branchname2,city,country B3,Branchname3,city,country B4,Branchname4,city,country B5,Branchname5,city,country RXD file : will... (11 Replies)
Discussion started by: satece
11 Replies

4. UNIX for Dummies Questions & Answers

UNIX one line cmd join 2 sets of data from 2 files

Hi all, This is my first and undoubtedly many posts to come. I'm new to using unix and would like a hand with this problem I have. What i'm trying to do is match 2 sets of data from 2 files and put result into file 3. Sounds simply but there is a catch, the match is a "partial field" match, if... (2 Replies)
Discussion started by: tugar
2 Replies

5. UNIX for Dummies Questions & Answers

How to use the the join command to join multiple files by a common column

Hi, I have 20 tab delimited text files that have a common column (column 1). The files are named GSM1.txt through GSM20.txt. Each file has 3 columns (2 other columns in addition to the first common column). I want to write a script to join the files by the first common column so that in the... (5 Replies)
Discussion started by: evelibertine
5 Replies

6. UNIX for Dummies Questions & Answers

Join 2 files with multiple columns: awk/grep/join?

Hello, My apologies if this has been posted elsewhere, I have had a look at several threads but I am still confused how to use these functions. I have two files, each with 5 columns: File A: (tab-delimited) PDB CHAIN Start End Fragment 1avq A 171 176 awyfan 1avq A 172 177 wyfany 1c7k A 2 7... (3 Replies)
Discussion started by: InfoSeeker
3 Replies

7. UNIX for Dummies Questions & Answers

Join multiple Split files in Unix

Hi, I have a big file of 50GB size. I need copy it to a second ftp from a ftp. I am not able to do the full 50GB transfer as it timesout after some time. SO i am trying to split the file into 5gb each 10 files with the below command. split -b 5368709120 pack.tar.gz backup.gz After I... (2 Replies)
Discussion started by: venu_nbk
2 Replies

8. Shell Programming and Scripting

Join two fixed length Files in Unix

Hi, Can we join two fixed length files in Unix using JOIN command? Is there any other command to accomplish the same? Thanks, G.Harikrishnan (6 Replies)
Discussion started by: gharikrishnan
6 Replies

9. Shell Programming and Scripting

How To create Flat Files using Unix Shell Script?

Hi all, How to create Flat Files using Unix Shell Script. The Script is supposed to be sheduled to run at a particular time? Thanks in advance Appu (4 Replies)
Discussion started by: Aparna_k82
4 Replies

10. UNIX for Advanced & Expert Users

building flat files in unix and importing them from windows

what is a flat file in unix? i have to import a unix flat files from windows based programme. my question is not to export from unix but only to import from windows only. how to build that flat files? how to create export to windows how to import from windows (3 Replies)
Discussion started by: tunirayavarapu
3 Replies
Login or Register to Ask a Question