join -t problem (newbie)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers join -t problem (newbie)
# 1  
Old 02-21-2010
join -t problem (newbie)

Been tearing my hair out trying to work out how to make the -t option in the join command work.

Joining two files on col 1; columns in both files are separated by tabs.

file1:

2010/02/01-00:00 10.63
2010/02/01-00:06 10.63
2010/02/01-00:12 10.61
2010/02/01-00:18 10.58
(there are LOTS more lines in this file)

File2:
2010/02/01-00:03 10.63 H
2010/02/01-06:06 -1.36 L
2010/02/01-12:21 11.39 H
2010/02/01-18:37 -1.82 L
2010/02/02-00:52 10.77 H
(more lines in this file too)

I've been using:

Code:
join -a1 -a2 -o '1.1 1.2 2.2 2.3' file1 file2 > resultFile.txt

but the only time the output (-o 1.1 1.2 2.2 2.3) begins to work is using -t:, but that is a problem due to the ':' in the timestamps. Whenever I try -t\t, -t'\t', -t"\t" it fails with the join help display.

How do I format a tab using -t?

OS 10.6.2, BASH shell iMac 2.8 ghz Intel Core 2 Duo
# 2  
Old 02-21-2010
What is the desired output, can you post it too?
# 3  
Old 02-21-2010
For example (tab separated columns)
file1:col1, col2:
2010/02/01-06:06 -1.36

file2: col1, col2, col3
2010/02/01-06:06 -1.36 L

what I'd like is:

2010/02/01-06:06 -1.36 -1.36 L

It may seem odd, but I'm using the result in gnuplot, with col1 & col2 to draw the curve, and col3 & col4 to label the high and low points of the curve (this is tidal data).

There might be a way around this in gnuplot but I'm at the beginning on a learning curve there too so for the moment I may need to do it this way.
# 4  
Old 02-22-2010
the code below works very well, just like you wanted. Id like to draw your attention to where I changed first line of 2.txt file same as first line of 1.txt, So no need to use anything except "-a" options.

Code:
cat 1.txt 
2010/02/01-00:00        10.63
2010/02/01-00:06        10.63
2010/02/01-00:12        10.61
2010/02/01-00:18        10.58

Code:
cat 2.txt 
2010/02/01-00:00        10.63   H
2010/02/01-06:06        -1.36   L
2010/02/01-12:21        11.39   H
2010/02/01-18:37        -1.82   L
2010/02/02-00:52        10.77   H

Code:
join -a1 -a2 1.txt 2.txt > 3.txt

Code:
cat 3.txt 
2010/02/01-00:00 10.63 10.63 H
2010/02/01-00:06 10.63
2010/02/01-00:12 10.61
2010/02/01-00:18 10.58
2010/02/01-06:06 -1.36 L
2010/02/01-12:21 11.39 H
2010/02/01-18:37 -1.82 L
2010/02/02-00:52 10.77 H

# 5  
Old 02-22-2010
That's great, many thanks for your time and help.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with Join Command

I have 2 files. File 1 is a daily file with only a bunch of IDs and a date column. File 2 has all the dump of IDs and their respective cost. I basically want an inner join. When I am picking a few rows from these files and joining, they work perfectly fine. But when I join the full files together,... (13 Replies)
Discussion started by: Varshha
13 Replies

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

3. UNIX for Dummies Questions & Answers

Problem when using join command

Dear all, I have two files (each only contains 1 column) as attached. I want to combined the two files and only show the common records in both files. But when I use join command only the last row was combined. Anyone know what is the problem? I don't know how to write the correct code to only... (2 Replies)
Discussion started by: forevertl
2 Replies

4. UNIX for Dummies Questions & Answers

problem with join

So I want to join two files that have a lot of rows The file named gen1 has 2 columns: head gen1 1008567 0.4026931012 1119535 0.7088912314 1120590 0.7093805634 1145994 0.7287952590 1148140 0.7313924434 1155173 0.7359550430 1188481 0.7598914553 1201155 0.7663406553 1206921... (2 Replies)
Discussion started by: peanuts48
2 Replies

5. UNIX for Dummies Questions & Answers

SOLVED: Join problem

Hello, Going through book, "Guide to UNIX Using Linux". I am doing one of the projects that has me writing scripts to join files. Here is my pnumname script and I am extracting the programmers names and numbers from the program file and redirecting the output to the file pnn. I then created a... (0 Replies)
Discussion started by: thebeav
0 Replies

6. Shell Programming and Scripting

Problem with Join command

Hi guyz Excuse me for posting simple question I tried join and sort and other perl commands but failed I have 2 files. 1st file contain single column with around 6000 values (rows). Second file contain 2 columns 1st column is the same column (in 1st file) but randomly ordered and second... (5 Replies)
Discussion started by: repinementer
5 Replies

7. Programming

newbie problem

Im new to gcc, vim etc... and I've been trying a simple hello world program and every time I try to compile any C program I get the following error message test.c :1:19: error: stdio.h: No such file or directory test.c : In function 'main': test.c :5: warning: incompatible implicit... (5 Replies)
Discussion started by: blowFish@ubuntu
5 Replies

8. Shell Programming and Scripting

A join problem?

Hi everybody, I am hoping somebody here will be either be able to solve my troubles or at least give me a push in the right direction :) . I am developing a shell script to read in 4 different files worth of data that each contain a list of: username firstname secondname group score I... (2 Replies)
Discussion started by: jamjamjammie
2 Replies

9. Shell Programming and Scripting

newbie problem

hi, I want to clarify this matter for a long time so here I come, I seen people use if ] or if or if (( some condition )) exactly what are the difference? Thanks! (2 Replies)
Discussion started by: mpang_
2 Replies

10. UNIX for Dummies Questions & Answers

newbie problem please help

I am running a sun enterpirse 420 r with solaris 7 on it . I have a mount that is at 100 percent. It is running oracle on it., not sure version. i cant seen to find what is taking up all the space. is there a ls comand that will tell me the size of a directory and all sub folders in it. or... (2 Replies)
Discussion started by: Thump
2 Replies
Login or Register to Ask a Question