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 6557339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:03:41+00:00 2026-05-25T13:03:41+00:00

Believe it or not, I’ve searched all over the internet and haven’t found a

  • 0

Believe it or not, I’ve searched all over the internet and haven’t found a working solution for this problem in AWK.

I have two files, A and B:

File A:

chr1   pos1   
chr1   pos2
chr2   pos1
chr2   pos2

File B:

chr1 pos1
chr2 pos1
chr3 pos2

Desired Output:

chr1 pos1
chr2 pos1

I’d like to join these two files to basically get the intersection between the two files based on the first AND second columns, not just the first. Since this is the case, most simple scripts won’t work and join doesn’t seem to be an option.

Any ideas?

EDIT: sorry, I didn’t mention that there are more columns than just the two I showed. I’ve only shown two in my example because I’m only interested in the first two columns between both files being identical, the rest of the data aren’t important (but are nonetheless in the file)

  • 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-05-25T13:03:42+00:00Added an answer on May 25, 2026 at 1:03 pm

    Hum, my idea is the following:
    Use join to merge the two files and correct with awk

    $ join  A B 
    chr1 pos1 pos1
    chr1 pos2 pos1
    chr2 pos1 pos1
    chr2 pos2 pos1
    
    $ join  A B | awk '{ if ($2==$3) printf("%s %s\n", $1, $2) }'
    chr1 pos1 pos1
    chr2 pos1 pos1
    

    Edit: given the edit, the join solution may still work (with options), so the concept remains correct (imo).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I do not believe that any of the questions I have searched on here
I have been working on this form for my php class. I can not
I have an ecommerce application that I believe is not properly caching all of
So I have a problem that I can not figure out. I am writing
I have performed some initial research, but have not found exactly what I am
I have a specific C bit-shifting scenario that I do not believe is covered
This is not homework, I don't have money for school so I am teaching
I do not believe this is possible, but I figure there are people out
I do not believe this question is a duplicate. I want rows in the
I have read through most every post on EF-SaveChanges and do not believe my

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.