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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:08:24+00:00 2026-05-11T20:08:24+00:00

I have two files where I want to perform union operation based on 1st

  • 0

I have two files where I want to perform union operation
based on 1st column:

file1.txt

foo 1
bar 2
qux 3

file2.txt

foo x
qux y
boo z

The result I hope to get is like this:

foo  1 x
bar  2 -
qux  3 y
boo  - z

where the empty fields of column 1 is padded
with “-“.

But why this join command doesn’t work as I expected?

$ join -a1 -a2 -e"-" file1.txt file2.txt

What’s the right way to 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-05-11T20:08:24+00:00Added an answer on May 11, 2026 at 8:08 pm

    “Important: FILE1 and FILE2 must be sorted on the join fields.” (from this online manpage).

    This problem #1. Problem #2 is worse: option -e is badly documented — only works in conjunction with -o, so for example:

    $ join -a 1 -a 2 -e'-' -o '0,1.2,2.2' sfile1.txt sfile2.txt
    bar 2 -
    boo - z
    foo 1 x
    qux 3 y
    

    where the s prefix name indicated files that I’ve sorted beforehand.

    Edit: man join explains the -o switch (so does the online manpage I point to above). It specifies the fields to output (1.2 means 2nd field from file 1, &c), or 0 to mean the join field, and is a comma-separated list. (I didn’t remember the 0 value, actually, so had originally given a clumsier solution requiring awk post-processing, but the current solution is better… and no awk needed!).

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

Sidebar

Related Questions

I have two files, and I want to perform some line-wise operation across both
I have two files, and want to combine/overwrite whole nodes based on a particular
I have two text files, I want to place a text in the middle
Suppose that you have two huge files (several GB) that you want to concatenate
i have the form, and i want to upload two files. here is the
I have two Java.io.File objects file1 and file2. I want to copy the contents
On windows, I have two source files and want to create a patch with
I have two files such as: File_1 c1,c2,c3,c4 File_2 c1,c3,c2,c4 DA,CA,DD,CD Thus, I want
i have two files with columns sorted by the value of the first column,
I have two tab delimited files: File 1: 12 rows and 1 column File

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.