join files with numbered index


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers join files with numbered index
# 1  
Old 11-14-2011
join files with numbered index

Hi all

I´m a newbie so maybe this question will make someone mad.
I am trying this command;
Code:
join -a1 -11 file1 file2 > file3

file1 looks like:
Code:
1
2
3
4
5
6
7
8
9
10
11

file2:
Code:
1    lkj    klj    lkj
2    lkj    lkj    lkj
3
7    lkj    lkj    lkj
8
9
11    lkk    kll    lkk

The output skips the row numbered 11
While googeling I saw that join only understands alphabetic sorting but there must be a way to do this. My aim is to join five 60,000,000 lined files for a genetic project.

If my question is stupid maybe it´s because i´m not english speaking or that i´m a newbe in unix, please answer anyway, anything is appreciated.

Thanx in advance

Moderator's Comments:
Mod Comment Please use code tags <- click the link!

Last edited by awe1; 11-14-2011 at 07:50 AM.. Reason: code tags, see PM
# 2  
Old 11-14-2011
What OS are you using?

Update:
I can't replicate the problem you get when using join. I am not missing line 11 but getting a warning about the input files being not sorted, where this can be surpressed with an option in GNU join. The -1 1 can be left out as this seems to be default and you didn't define -2 1 anyway.

You can try this with awk:
Code:
$> awk 'NR==FNR{_[$1]=$0; next} _[$1] {print _[$1]; next} {print $0}' f2 f1
1    lkj    klj    lkj
2    lkj    lkj    lkj
3
4
5
6
7    lkj    lkj    lkj
8
9
10
11    lkk    kll    lkk


Last edited by zaxxon; 11-14-2011 at 08:09 AM.. Reason: update
# 3  
Old 11-14-2011
Is "Red Hat" a correct answer?

Now I´m confused, sometimes it works, sometimes not.
Now it complains that they are not sorted but still does the right thing.
The input files were originally created in the evil windows so that was maybe the problem.
It still is not trust worthy to get a warning when you want to trust the output file 100%

Thanx for the reply I´ll try the awk solution.

p.s. I was once nicknamed saxon

Last edited by awe1; 11-14-2011 at 08:47 AM..
# 4  
Old 11-14-2011
Heh, my name comes from an old arcade game though^^

"Red Hat" is ok - so we know it is Linux and you most probably use GNU versions of tools etc. There is incompatibility between some tools from different Linux'es and Unix'es.

It could be the case that ^M is causing a problem, if the file comes from windows. Could try the following to ensure a constant behaviour:
Code:
tr -d '\015' < f1 > f1.new
tr -d '\015' < f2 > f2.new
join -a1 f1.new f2.new

# 5  
Old 11-14-2011
Yes the problem was some kind of linefeed issue

dos2unix does help

Saxon is a Rock group
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 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

Shell Scripting - Select multiple files from numbered list

I am trying to have the user select two files from a numbered list which will eventually be turned into a variable then combined. This is probably something simple and stupid that I am doing. clear echo "Please Select the Show interface status file" select FILE1 in *; echo "Please Select the... (3 Replies)
Discussion started by: dis0wned
3 Replies

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

4. Shell Programming and Scripting

how to extract data from numbered files using linux in the numerical order-

Hi experts, I have a list of files containing forces as the only number as follows. Force1.txt Force2.txt Force3.txt Force4.txt Force5.txt . . . . . . . . . Force100.txt I want to put all the data(only a number ) in these forces files in the file with the same order like 1,2,3 ..100 .... (2 Replies)
Discussion started by: hamnsan
2 Replies

5. Shell Programming and Scripting

renaming numbered files

Hi there, I've got a set of files that are named as follows: image_N1_8letters.jpg image_N2_8letters.jpg ... image_N10_8letters.jpg image_N11_8letters.jpg .... image_N100_8letters.jpg image_N101_8letters.jpg with the "8letters" bit always consisting of 8 but always different... (3 Replies)
Discussion started by: kjartan
3 Replies

6. Shell Programming and Scripting

rename numbered files to numbered files with leading zeroes

Hi, I have some hundreds/thousands of files named logX.dat, where X can be any integer, and they are sequential, X ranges between 1 and any number: log1.dat log2.dat log3.dat log6.dat log10.dat ... log6000.dat I would like to rename them to scatter_params_0001.dat... (6 Replies)
Discussion started by: pau
6 Replies

7. Shell Programming and Scripting

Need help with generating m3u files in numbered directories

Hello: First, I have no idea what to search for on this task, so I'll just spell it out. I have the Bible in Audio format and each book is in a directory of it's own. 01 to 66 accordingly. I need a script to walk through each of them and ls *.mp3 > directory|book.m3u without the preceding... (2 Replies)
Discussion started by: Habitual
2 Replies

8. Shell Programming and Scripting

Listing even numbered files

Hi All, Could you please help in this case? Case: there's a directory 'CKMDB' in this directory, there are 30 files named in this manner 1.txt 2.txt 3.txt .... 30.txt Could you please guide me how to list only even numbered files like 2.txt... (5 Replies)
Discussion started by: xsam
5 Replies

9. 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
Login or Register to Ask a Question