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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:22:53+00:00 2026-05-28T06:22:53+00:00

I have two variables which are comma separated lists. I would like to join

  • 0

I have two variables which are comma separated lists. I would like to join these two variables by appending the lines based on their unique id.

Example below:

var1="
id1,data1,data2,data3
id2,data1,data2,data3
id3,data1,data2,data3
id4,data1,data2,data3
"

var 2="
id1,data4,data5,data6
id2,data4,data5,data6
id3,data4,data5,data6
id4,data4,data5,data6
"

output="
id1,data1,data2,data3,data4,data5,data6
id2,data1,data2,data3,data4,data5,data6
id3,data1,data2,data3,data4,data5,data6
id4,data1,data2,data3,data4,data5,data6
"

I’m not the best at AWK and while I can decrypt it I still have troubles coming up with commands. If you could help that would be great!

  • 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-28T06:22:54+00:00Added an answer on May 28, 2026 at 6:22 am

    If you’re not set on sed or awk, you can use join:

    $ cat in1
    id1,data1,data2,data3
    id2,data1,data2,data3
    id3,data1,data2,data3
    id4,data1,data2,data3
    x
    $ cat in2
    id1,data4,data5,data6
    id2,data4,data5,data6
    id3,data4,data5,data6
    id4,data4,data5,data6
    y
    $ join -t, -j1 in1 in2
    id1,data1,data2,data3,data4,data5,data6
    id2,data1,data2,data3,data4,data5,data6
    id3,data1,data2,data3,data4,data5,data6
    id4,data1,data2,data3,data4,data5,data6
    $ join -t, -a1 -a2 -j1 in1 in2
    id1,data1,data2,data3,data4,data5,data6
    id2,data1,data2,data3,data4,data5,data6
    id3,data1,data2,data3,data4,data5,data6
    id4,data1,data2,data3,data4,data5,data6
    x
    y
    

    Use the -a1 -a2 options if you want to see unmatched lines, otherwise don’t.

    Note that the files need to be sorted, if they’re not already, you can use the sort command for that.

    sort in1 > in1.sorted
    sort in2 > in2.sorted
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a javascript which takes two variables i.e two lists one is a
I have anonymous type variable which i am populating like that(i have two variables
I have two string variables which are both file paths. The code that worked
I have an irregular mesh which is described by two variables - a faces
I have two Python functions, both of which take variable arguments in their function
I have two variables : count, which is a number of my filtered objects,
I have two integer variables which I need to divide in order to work
I have two or more variables of class object in c# which has integer
I have a function f(x,y) of two variables, of which I need to know
I have a class MyClass , which contains two member variables foo and bar

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.