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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:44:50+00:00 2026-06-12T16:44:50+00:00

i have two files file1 ——————————- 1 a t p b 2 b c

  • 0

i have two files

file1
-------------------------------
1      a      t      p      b
2      b      c      f      a
3      d      y      u      b
2      b      c      f      a
2      u      g      t      c
2      b      j      h      c

file2
--------------------------------
1   a   b
2   p   c
3   n   a
4   4   a

i want combine these 2 files based last columns (column 5 of file1 and column 3 of file2) using awk

result
----------------------------------------------
1      a      t      p     1   a   b
2      b      c      f     3   n   a
2      b      c      f     4   4   a
3      d      y      u     1   a   b
2      b      c      f     3   n   a
2      b      c      f     4   4   a
2      u      g      t     2   p   c
2      b      j      h     2   p   c
  • 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-12T16:44:51+00:00Added an answer on June 12, 2026 at 4:44 pm

    at the very beginning, I didn’t see the duplicated “a” in file2, I thought it would be solved with normal array matching. … now it works.

    an awk onliner:

     awk 'NR==FNR{a[$3"_"NR]=$0;next;}{for(x in a){if(x~"^"$5) print $1,$2,$3,$4,a[x];}}' f2.txt f1.txt
    

    test

    kent$  head *.txt  
    ==> f1.txt <==
    1      a      t      p      b
    2      b      c      f      a
    3      d      y      u      b
    2      b      c      f      a
    2      u      g      t      c
    2      b      j      h      c
    
    ==> f2.txt <==
    1   a   b
    2   p   c
    3   n   a
    4   4   a
    
    kent$  awk 'NR==FNR{a[$3"_"NR]=$0;next;}{for(x in a){if(x~"^"$5) print $1,$2,$3,$4,a[x];}}' f2.txt f1.txt 
    1 a t p 1   a   b
    2 b c f 3   n   a
    2 b c f 4   4   a
    3 d y u 1   a   b
    2 b c f 3   n   a
    2 b c f 4   4   a
    2 u g t 2   p   c
    2 b j h 2   p   c
    

    note, the output format was not sexy, but it would be acceptable if pipe it to column -t

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

Sidebar

Related Questions

I have two files I merged them based key using below code file1 -------------------------------
I have two files, and want to combine/overwrite whole nodes based on a particular
I have two FASTA files: file1.fasta >foo ATCGGGG >bar CCCCCC file2.fasta >qux ATCGGAAA What
I have two files. file1 has the data like belowing containing only one column.
I have the following two files: file1.c int main(){ foo(); return 0; } file2.c
I have two files, file1 and file2. I have to modify file1 in a
I have two C++ files, say file1.cpp and file2.cpp as //file1.cpp #include<cstdio> void fun(int
So I have two different files somewhat like this: file1.py from file2 import *
I have two files I'm trying to join/merge based on columns 1 and 2
say I have two files: file1 and file2 is there a single command that

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.