A simple join, but nothing is working out for me


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers A simple join, but nothing is working out for me
# 1  
Old 02-21-2013
A simple join, but nothing is working out for me

Guys,

I want to join two files. You might have seen this many times. I just don't get the desired output.

Searching the forum, No proper links Smilie

Input:
Code:
File1
test1
test2
test3

Code:
File2
is bad
is not bad


Output Needed:
Code:
test1 is bad
test2 is bad
test3 is bad
test1 is not bad
test2 is not bad
test3 is not bad

# 2  
Old 02-21-2013
You have to have a key for the files to join.
Please make your files to have a key like this
Code:
--File1
1 test1
1 test2
1 test3

Code:
--File2
1 is bad
1 is not bad

And run this command:
join -a1 file1.txt file2.txt

That will produce an output of
Code:
1 test1 is bad
1 test1 is not bad
1 test2 is bad
1 test2 is not bad
1 test3 is bad
1 test3 is not bad

You can remove the key from output using awk or sed.
# 3  
Old 02-21-2013
Code:
while read LINEF2
do
   while read LINEF1
   do
      echo $LINEF1 " " $LINEF2
   done < file1
done < file2
test1   is bad
test2   is bad
test3   is bad
test1   is not bad
test2   is not bad
test3   is not bad

# 4  
Old 02-21-2013
Not really a join, no different keys, just a cartesian product. Choose the output using -o: Man Page for join (opensolaris Section 1) - The UNIX and Linux Forums
# 5  
Old 02-21-2013
Code:
awk 'NR==FNR{a[$0]=$0;next}{for(i in a) print a[i],$0}' file1 file2

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX Join not working as expected

Hello All, I'm working on a Shell script to join data from two files using Join command but not able to get the desired output as its throwing me an error: I have sorted the two files on the Column 1 numerically which is used as Join clause File 1: 1,ABC,GGG,20160401 2,XYZ,KKK,20160401... (2 Replies)
Discussion started by: venkat_reddy
2 Replies

2. UNIX for Dummies Questions & Answers

Join not working

Hi all, I'm trying to use the join command to merge two files, but it's not finding lots of the matches. I have three files in total: File A: 31_77 34_46 72_61 85_10 85_23 110_33 144_45 154_25 154_90 170_5 170_44 217_63 255_19 333_20 333_23 333_32 (2 Replies)
Discussion started by: HEP
2 Replies

3. Shell Programming and Scripting

Join not working properly

I want to join two files , with file 1 col 3 and file 2 col 1 as key. The join command is erratic for some reason. File 2 is a master file having all the names, and file 1 has some values. I want to add the names from fil2 in file 1. If I use the original master file, some output is missing. ... (16 Replies)
Discussion started by: ritakadm
16 Replies

4. Shell Programming and Scripting

Join not working for comparision

Hi All, I have 2 files where the first column of both the files have to be compared and if they match the first six columns of the first file to be extracted in the output file. Format of files : File1 : ${SHTEMP}NPBR5.XTR.tmp S00016678|129|7|MPF|20090106|E... (3 Replies)
Discussion started by: nua7
3 Replies

5. Shell Programming and Scripting

Bash join script not working

So i'm currently working on a project where I'm attempting to display information of users from the /etc/passwd file and also another information file holding addition information about users. Problem is I've been trying to join the two files together and have all of the information about each... (2 Replies)
Discussion started by: Nostyx
2 Replies

6. Shell Programming and Scripting

simple join for multiple files and produce 3 outputs

sh script file1 filea fileb filec ................filez. >>output1 & output2 &output3 file1 z10 1873 1920 z_number1_E59 z10 2042 2090 z_number2_E59 Z22 2476 2560 z_number3_E59 Z22 2838 2915 z_number4_E59 z1 1873 1920 z_number1_E60 z1 ... (9 Replies)
Discussion started by: stateperl
9 Replies

7. Shell Programming and Scripting

Merging fields --- Join is not working

Hi GUYS sorry for putting simple query. I have tried the methods posted previously in this site but I'm unable to join the similar values in different columns of different files. I used sort -u file1 and join but no use.?? I'm attaching my inputfiles.Plz chek them I have two files. 1st file... (10 Replies)
Discussion started by: repinementer
10 Replies

8. Shell Programming and Scripting

Problems using join for simple database lookup

I am trying to get a script working that will perform a simple database lookup using the join command. Here are the two files that I am trying to join: % cat lookup1.txt Number_1 Other_data_a Number_5 Other_data_b Number_8 Other_data_c Number_10 Other_data_d % cat... (2 Replies)
Discussion started by: JasonHamm
2 Replies

9. Shell Programming and Scripting

simple grep is not working for me

Hi, On the log Netscape log, I need to grep for 500 error. I am doing that but I also get 1500 in that same log. cat access |grep "500" Results: "GET /css/RBR.css HTTP/1.1" 200 15000 304 - - - 399 639 523 164 0 This not what I need... Please advice. (4 Replies)
Discussion started by: samnyc
4 Replies

10. UNIX for Dummies Questions & Answers

join not working

I was trying to merge the following two example files using their first field: join -1 1 -2 1 file1 file 2 but nothing is produced. The expected result should be: rs1005152 7 q21.3 3 It appears that the length of the first field in file1 is causing the problem. Any suggesting on how to... (12 Replies)
Discussion started by: gamma_user
12 Replies
Login or Register to Ask a Question