Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8269913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:23:19+00:00 2026-06-08T06:23:19+00:00

I posted a question before a week and the answer was simply (use join):

  • 0

I posted a question before a week and the answer was simply (use join):

join <(sort file1) <(sort file2) >output

to join files that have something common which is usually the first field.

I have the following two files:

genes.txt

ENSG001 ENSG002
ENSG002 ENSG001
ENSG003 ENSG004

features.txt

ENSG001 400
ENSG002 350
ENSG003 210
ENSG004 100

I need to join these two files to be like this:

output.txt

ENSG001 400 ENSG002 350
ENSG002 350 ENSG001 400
ENSG003 210 ENSG004 100

I know the answer is in join command but I can’t figure out how to join based on two fields. I tried

join -j 1 <(sort genes.txt) <(sort features.txt) >attempt1.txt

but the result will looks like this:

attempt1.txt

ENSG001 ENSG002 400
ENSG002 ENSG001 350
ENSG003 ENSG004 210

I then tried

join -j 2 <(sort -k 2 genes.txt) <(sort -k 2 features.txt) >attempt2.txt

attempt2.txt is empty

Does (join) have the ability to join two files based on two fields ? If no then how can I do it ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:23:21+00:00Added an answer on June 8, 2026 at 6:23 am

    Thank you all guys I have managed to answer it by tricking the problem.

    First I joined the files normally, I then changed the position of first and second field, I next joined the modified output file another time with features, and finally I switched the positions of fields again.

    join <(sort genes.txt) <(sort features.txt) >tmp
    
    cat tmp | awk '{ print $2, $1, $3 }' >tmp2
    
    join <(sort tmp2) <(sort features.txt) >tmp3
    
    cat tmp3 | awk '{ print $2, $3, $1, $4 }' >output.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been posted before... but I haven't found any answer
Stumped here. Posted a similar question before. We have a pretty large WPF app
I know i have posted a similar question before but i am not able
I have posted a question before, Moving away from VSS , in which I
I have posted a similar question before why my local object destroyed twice? but
I have posted a question about a similar issue before, and managed to fix
I have posted a question about a similar issue before, and managed to fix
First off I apologize... I have posted this question before, but I did a
I already posted a question regarding it, but at that time I haven't have
I posted this basic question before, but didn't get an answer I could work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.