Join command help with spacing

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Join command help with spacing
# 1  
Old 05-01-2010
Join command help with spacing

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
I have to join 3 files numerically according to ID(first column) with no comments. In the end i'll be something like this to a Marks file.

54546547 7 7 5
12345678 4 5 6
etc

What I think my problem is, is that there's something wrong with my first join. despite my final output being spaced correctly.

When i submit it to the system that checks my program it says:
Code:
 File: Marks
Expected: 26825845 4 8
Got: 26825845  4 8

I have 3 files Prac1, Prac2 and Prac3. Each student cannot have missed all pracs but can miss 2. So they have to have some marks.
Code:
# Results for Prac1. The format is:
# 12345678 10
32145645 4
12345678 7
321435355 3
4325325 3
54359506 5
4325459 5
87686546   
90948695

Code:
# Results for Prac2. The format is:
# 12345678 3
12345678  
32145645 3
87686546 9
4325459 5
90948695 3
321435355

Code:
# Results for Prac3. The format is:
# 12345678 3
12345678 1
87686546 8
32145645
321435355 3
54359506 4
4325325 3
90948695 7

2. Relevant commands, code, scripts, algorithms:
I must use join and sort nothing else. So no awk solutions. Must be sorted numerically.


3. The attempts at a solution (include all code and scripts):
Code:
grep -v "#" Prac1 | sort > Prac1temp1
grep -v "#" Prac2 | sort > Prac2temp2
join -a1 -a2 -o "0 1.2 2.2"  Prac1temp1 Prac2temp2 > part1temp1

grep -v "#" Prac3 | sort > Prac3temp3
join -a1 -a2 -t" " -e" " -o "0 1.2 1.3 2.2" part1temp1 Prac3temp3 > part1temp2
sort -n part1temp2 > Marks

part1temp1
Code:
12345678 7 
321435355 3 
32145645 4 3
4325325 3 
4325459 5 5
54359506 5 
87686546  9
90948695  3

Marks
Code:
4325325 3   3
4325459 5 5  
12345678 7   1
32145645 4 3  
54359506 5   4
87686546   9 8
90948695   3 7
321435355 3   3

If you notice in my final output(Marks) it's fine. sorted numerically, spacing is good. but in part1temp1 the id's 87686546 and 90948695's marks are supposed to have moved over by 1 space as they are prac2 marks.

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Monas University, Melbourne, Vic, Australia, John Hurst, FIT3042

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

sorry i've solved it. it was the way the question was written. didn't need to leave a space for empty pracs.

Last edited by bigubosu; 05-01-2010 at 11:40 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Join Command

Hi, Please explain the working process of join command. File 1 P B S A C AFile2 C B P A S DBut the output of join command is... join File1.txt File2.txt P B A S A DBut I guess the output should be P B A S A D C A BPlease correct me,if i am worong or missing some thing. Thanks (2 Replies)
Discussion started by: satyar
2 Replies

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

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

4. UNIX for Dummies Questions & Answers

paste command without spacing?

I'm trying to combine text files without a space. So if i use the paste command paste file1 file2 file3 > file4 the new file created has spacing between the contents of the once individual files. Is there some trick I can do with a delimiter that removes the spaces.. like paste -d'' or... (1 Reply)
Discussion started by: steveinthebox
1 Replies

5. Shell Programming and Scripting

awk command for simple join command but based on 2 columns

input1 a_a a/a 10 100 a1 a_a 20 200 b1 b_b 30 300 input2 a_a a/a xxx yyy a1 a1 lll ppp b1 b_b kkk ooo output a_a a/a 10 100 xxx yyy (2 Replies)
Discussion started by: ruby_sgp
2 Replies

6. Shell Programming and Scripting

using join command

I am given: Sara:Smith:11234:3:63498:25:40 Perry:Potter:12445:2:35664:15:40 Ann:Abbott:23323:2:54865:22:42 Maple:Myers:24223:1:63498:18:35 Harold:Hanson:35664:2:54865:10:40 Bob:Brown:40778:1:24223:15:40 Jane:Jones:41288:1:53498:24:40 Wanda:Wallace:51122:4:63498:55:40... (4 Replies)
Discussion started by: ehshi1992
4 Replies

7. Shell Programming and Scripting

join command

All, I have 3 files (tab seperated): Note: Please treat dash (-) as empty value in the file, I have added it to make input easily readable file1: (2 cols) A 1 B 2 C 3 file2: (4 cols - col4 has empty values for 4th column except 2nd row) A 1 5 - B 2 6 Y C 3 7 - D 4 8 - file3... (1 Reply)
Discussion started by: bgmmk
1 Replies

8. Shell Programming and Scripting

Join command

Dear Experts, I have several (say 'm') text files, each with 'n' columns. I want to put them into a large single file with n*m columns. a 1 a 1 a 1 a 1 b 2 b 5 b 1 b 3 c 3 c 7 ... (1 Reply)
Discussion started by: Mish_99
1 Replies

9. Shell Programming and Scripting

join (pls help on join command)

Hi, I am a new learner of join command. Some result really make me confused. Please kindly help me. input: file1: LEO oracle engineer 210375 P.Jones Office Runner ID897 L.Clip Personl Chief ID982 S.Round UNIX admin ID6 file2: Dept2C ID897 6 years Dept5Z ID982 1 year Dept3S ID6 2... (1 Reply)
Discussion started by: summer_cherry
1 Replies

10. Shell Programming and Scripting

join command

Hi, I'm using the join command and it appears to discard certain fields. Here are the two files i'm comparing: File1: 1 a 2 b 3 c 4 d 99 f 101 g 999 i 200 j File 2: 1 e 2 f 3 g 4 h 99 h (22 Replies)
Discussion started by: penfold
22 Replies
Login or Register to Ask a Question