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

  • SEARCH
  • Home
  • 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 8797647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:53:42+00:00 2026-06-13T23:53:42+00:00

I want to join two files and index them in a new column as

  • 0

I want to join two files and index them in a new column as show below :

file A

apple     1 2 3 4 5 6
banana    3 2 4 4 5 6
orange    2 3 4 5 6 7
pear      2 4 5 6 3 5

file B

apple    1 3 4 5 6 7
grapes   4 5 6 4 3 6
melon    3 4 5 2 5 1
orange   2 4 5 6 7 8

I want to compare the two files based on first two columns, and output the common rows from file A and then add unique rows from both file A and file B and index them as shown below

output:

apple     1 2 3 4 5 6 both
orange    2 3 4 5 6 7 both
banana    3 2 4 4 5 6 fileA
pear      2 4 5 6 3 5  fileA
grapes   4 5 6 4 3 6   fileB
melon    3 4 5 2 5 1   fileB
  • 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-13T23:53:43+00:00Added an answer on June 13, 2026 at 11:53 pm

    comm compares two files and reports which lines occur in one, the other or both:

    comm -2 <(cut -f1 -d' ' fileA | sort)
            <(cut -f1 -d' ' fileB | sort) \
      | sed $'/\t/{s/$/ both/;s/\t//};/ /!s/$/ fileA/' \
      | join -o1.1,2.2,2.3,2.4,2.5,2.6,2.7,1.2 - fileA \
      | sort -k8
    cut -f1 -d' ' fileA \
      | grep -vFf- fileB \
      | sed 's/$/ fileB/'
    

    As you can see, the pipeline is pretty complicated. If you plan to make changes to the code, consider moving to a more powerful language like Perl.

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

Sidebar

Related Questions

I'd like to join two files in bash using a common column. I want
I have two CSV files with a common column and I want to Join
I want to join two tables (below) which i get. But then I want
My situation is I have two tables. I want to join them together and
I want to add two files together, which one of them has only 1
Very often I want to join two ascii-files, which are both tables in the
I want to join two tables using JPQL : SELECT * FROM A LEFT
I want to join two strings each representing a relative URL in Javascript. I
I want to join two tables with several hundred columns, like this: select *
I have two tables that I want to join together. Table1 Year, ID, Theme,

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.