Join Two Files, Each With Different Delimiters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Join Two Files, Each With Different Delimiters
# 1  
Old 04-21-2013
Join Two Files, Each With Different Delimiters

Hello All,

I am trying to join two files, each with differing delimiters. file1 has

doe, john 10.00 60.00 4.00 5.00
doe, jane 10.00 60.00 4.00 5.00

...while file2 has the following content:

doe, johnz 10.00::60.00:4.00:5.00
doe, janet 10.00:60.00::4.00:5.00

Currently, I have join -1 1 -2 1 file1 file2 > file3 and the output only shows two of many lines and repeats some content on each line. Any idea how to ensure both files are joined and all lines are on the output?
# 2  
Old 04-21-2013
Code:
$ join -1 1 -2 1 file1 file2
doe, john 10.00 60.00 4.00 5.00 johnz 10.00::60.00:4.00:5.00
doe, john 10.00 60.00 4.00 5.00 janet 10.00:60.00::4.00:5.00
doe, jane 10.00 60.00 4.00 5.00 johnz 10.00::60.00:4.00:5.00
doe, jane 10.00 60.00 4.00 5.00 janet 10.00:60.00::4.00:5.00

What is it you don't like about the result?
# 3  
Old 04-21-2013
Quote:
Originally Posted by hanson44
Code:
$ join -1 1 -2 1 file1 file2
doe, john 10.00 60.00 4.00 5.00 johnz 10.00::60.00:4.00:5.00
doe, john 10.00 60.00 4.00 5.00 janet 10.00:60.00::4.00:5.00
doe, jane 10.00 60.00 4.00 5.00 johnz 10.00::60.00:4.00:5.00
doe, jane 10.00 60.00 4.00 5.00 janet 10.00:60.00::4.00:5.00

What is it you don't like about the result?
The same code seems to be working fine now, not sure why the system delivered bad output several times earlier. Thanx for the prompt response.
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. UNIX for Dummies Questions & Answers

Comparing two files having different delimiters

hi, i have a file called OVER90.txt and it's contents are as below: over90.txt: ------- UNIQUENAME 2013-12-06 11:23:48.1 UNIQUENAME2 2014-03-10 12:22:29.91 UNIQUENAME3 2013-04-02 10:41:22.1 UNIQUENAME4 2014-07-07 10:43:57.953 The ldap_jcon file's contents are as below: ... (8 Replies)
Discussion started by: dickie.sanders
8 Replies

3. Shell Programming and Scripting

How to put delimiters in text files after fix characters?

Hi , i have a text file in which i want to put delimiters after certain characters ( fix),. like put a delimiter (any like ,) after 1-3 character than 4 than 5 than 6-17 ..... files looks like this (original)... (8 Replies)
Discussion started by: anamdev
8 Replies

4. 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

5. UNIX for Dummies Questions & Answers

how to join two files using "Join" command with one common field in this problem?

file1: Toronto:12439755:1076359:July 1, 1867:6 Quebec City:7560592:1542056:July 1, 1867:5 Halifax:938134:55284:July 1, 1867:4 Fredericton:751400:72908:July 1, 1867:3 Winnipeg:1170300:647797:July 15, 1870:7 Victoria:4168123:944735:July 20, 1871:10 Charlottetown:137900:5660:July 1, 1873:2... (2 Replies)
Discussion started by: mindfreak
2 Replies

6. UNIX for Dummies Questions & Answers

comparing two files having different delimiters using awk

hi, i have a file called file1.txt and it's contents are as below: file1.txt: ------- abc,123, thomas dab,234,muller gab,456,ram The lookup file's contents are as below: lookup.txt ---------- abc|japan dcd|US dab|china gab|brazil (3 Replies)
Discussion started by: amar1003
3 Replies

7. 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

8. Shell Programming and Scripting

Join TWO Files

Hi, I would like to Join the Below mwntioned TWO Files. File 1.txt --------- 99|Table1|00|5 99|Table2|00|10 99|Table3|00|15 99|Table1|04|7 File 2.txt --------- 99|Table1|00|INF1 99|Table2|00|INF2 99|Table3|00|INF3 99|Table1|04|INF4 99|Table4|04|INF5 99|Table2|04|INF6 Expected... (3 Replies)
Discussion started by: krk_555
3 Replies

9. Shell Programming and Scripting

join command and delimiters

I am using the join command to join information from two files that have a common field. Here are some examples: field1: 99900 543 99903 333 99998 120 10000 222 100001 333 100005 220 field2: 99900 2009-05 99903 2009-05 99998 2009-05 100000 2009-05 100001 2009-05... (4 Replies)
Discussion started by: manouche
4 Replies

10. Shell Programming and Scripting

join files

Hi , I want to join 2 files based on 2 column join condition. a11 john 2230 5000 a12 XXX 2230 A B 200 345 Expected O/P John 2230 5000 A B 200 I have tried this awk 'NR==FNR{a=$1;next}a&&sub($1,a)' a11 a12 > a13 (3 Replies)
Discussion started by: mohan705
3 Replies
Login or Register to Ask a Question