Questions tagged [join]

Join several lines in a single one, inside a single file or from several files.

join is a utility in Unix systems that takes two files and a field number for each and outputs a file where the lines with an identical field in both are merged.

For example, given a file a:

a hey
b how are you ?
c ok

and a file b:

a hi
b fine, thank you
d er...

join -1 1 -2 1 a b outputs:

a hey hi                                           
b how are you ? fine, thank you

"Join" is also a common operation in text editors. Joining several lines means basically removing the end of lines between them (and optionally, replacing them with regular spaces), effectively making them a single line.

249 questions
46
votes
3 answers

How to merge two files based on the matching of two columns?

I have file1 likes: 0 AFFX-SNP-000541 NA 0 AFFX-SNP-002255 NA 1 rs12103 0.6401 1 rs12103_1247494 0.696 1 rs12142199 0.7672 And a file2: 0 AFFX-SNP-000541 1 0 AFFX-SNP-002255 1 1 rs12103 0.5596 1 …
Dadong Zhang
  • 669
  • 1
  • 7
  • 10
20
votes
7 answers

join : "File 2 not in sorted order"

I've got two files _jeter3.txt and _jeter1.txt I've checked they are both sorted on the 20th column using sort -c sort -t ' ' -c -k20,20 _jeter3.txt sort -t ' ' -c -k20,20 _jeter1.txt #no errors but there is an error when I want to join…
Pierre
  • 1,713
  • 3
  • 15
  • 21
11
votes
2 answers

Join two files with matching columns

File1.txt id No gi|371443199|gb|JH556661.1| 7907290 gi|371443198|gb|JH556662.1| 7573913 gi|371443197|gb|JH556663.1| 7384412 gi|371440577|gb|JH559283.1| 6931777 File2.txt id …
jack
  • 3,853
  • 11
  • 28
  • 33
10
votes
2 answers

join multiple lines based on column1

I have a file like below.. abc, 12345 def, text and nos ghi, something else jkl, words and numbers abc, 56345 def, text and nos ghi, something else jkl, words and numbers abc, 15475 def, text and nos ghi, something else jkl,…
pvkbhat
  • 101
  • 1
  • 1
  • 3
9
votes
5 answers

Compare two files with first column and remove duplicate row from 2nd file in shell script

I will ask my question with an example. I have 2 files: File #1: 118D FC300_R5_TP FX.B 32775 2112 6 2038 6 2112 0 118E FC300_R5_TP FX.B 32775 2136 7 2065 6 2136 0 118F FC300_R5_TP FX.B …
Rahul Rana
  • 99
  • 1
  • 1
  • 2
9
votes
5 answers

Joining two files with unique identifier

I have two files with approximately 12900 and 4400 entries respectively, that I want to join. The files contain location information for all landbased weather observing stations around the globe. The largest file is updated biweekly, and the smaller…
9
votes
3 answers

Join, filling in missing key values

I have two files having a primary key value as a first field, and a corresponding value(s) as the remaining fields, and some primary key values are missing in one of them but are present in another, and vice versa: $ cat jointest1.txt jointest2.txt …
mbaitoff
  • 4,911
  • 8
  • 28
  • 32
8
votes
2 answers

A shell script for joining two files

I want to write a shell script that get two files A and B, and get a result like this: File A: user_a tel_a addr_a user_b tel_b addr_b File B: process_1 user_a process_2 user_a process_3 user_b And the result: user_a process_1 tel_a addr_a user_a…
Navid Farhadi
  • 411
  • 1
  • 7
  • 13
8
votes
5 answers

Compare an old file and new file, but ignore lines which only exist in new file?

I have two files: oldlist - This contains a list of files and a md5 hash for each file. This was generated one year ago. newlist - This also contains a list of files and a md5 hash for each file. However, some files have been changed (e.g. their…
Stefan Lasiewski
  • 19,264
  • 24
  • 70
  • 85
7
votes
1 answer

intersection of two files according to the first column

I have two files in file A, there are sequence_numbers in the other file B, there are many columns, and the first column is sequnce numbers, I want to get a files with all the lines in the B with the sequence numbers which are in the A how can I…
wenzi
  • 403
  • 2
  • 6
  • 9
7
votes
4 answers

Join two files each with two columns, including non-matching lines

I'm trying to match and merge two sets of sorted data, one set per file. Each file contains two columns: the key field and the associated value. The resulting output should contain three columns: the key field, the value (if any) from the first…
roaima
  • 107,089
  • 14
  • 139
  • 261
7
votes
4 answers

Matching and pasting to line

So I have 2 very big text files, consisting of lines like…
user104391
  • 71
  • 2
7
votes
4 answers

How to merge two files with different number of rows in shell?

I have file1 like this: CHR SNP TEST A1 A2 GENO O(HET) E(HET) P 0 AFFX-SNP-000541 ALL 0 0 0/0/0 nan nan 1 0 …
Dadong Zhang
  • 669
  • 1
  • 7
  • 10
7
votes
5 answers

Join two files, matching on a column, with repetitions

How can I get two files A and B, and out put a result like this: File A: 001 Apple, CA 020 Banana, CN 023 Apple, LA 045 Orange, TT 101 Orange, OS 200 Kiwi, AA File B: 01-Dec-2013 01.664 001 AAA CAC 1083 01-Dec-2013 01.664 020 AAA CAC…
JOSS
  • 95
  • 1
  • 6
6
votes
4 answers

How to join a line with a pattern with the next line with sed?

I can't find this case in the board, so I'm asking the question. This is input file: module x(a,b,c) module y(d,e,f, g,h,i) module z(j,k,l) And output file should be: module x(a,b,c) module y(d,e,f, g,h,i) module z(j,k,l)
funfun
  • 89
  • 1
  • 1
  • 4
1
2 3
16 17