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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:50:09+00:00 2026-06-14T22:50:09+00:00

I have 2 tabular files. One file contains a mapping of 50 key values

  • 0

I have 2 tabular files. One file contains a mapping of 50 key values only called lookup_file.txt.
The other file has the actual tabular data with 30 columns and millions of rows. data.txt
I would like to replace the id column of the second file with the values from the lookup_file.txt..

How can I do this? I would prefer using awk in bash script..
Also, Is there a hashmap data-structure i can use in bash for storing the 50 key/values rather than another 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-06-14T22:50:10+00:00Added an answer on June 14, 2026 at 10:50 pm

    Assuming your files have comma-separated fields and the “id column” is field 3:

    awk '
    BEGIN{ FS=OFS="," }
    NR==FNR { map[$1] = $2; next }
    { $3 = map[$3]; print }
    ' lookup_file.txt data.txt
    

    If any of those assumptions are wrong, clue us in if the fix isn’t obvious…

    EDIT: and if you want to avoid the (IMHO negligible) NR==FNR test performance impact, this would be one of those every rare cases when use of getline is appropriate:

    awk '
    BEGIN{
       FS=OFS=","
       while ( (getline line < "lookup_file.txt") > 0 ) {
          split(line,f)
          map[f[1]] = f[2]
       }
    }
    { $3 = map[$3]; print }
    ' data.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file that contains one set of data and this has
I have designed a tabular report in SSRS which has columns Student Name, Quarter
I have a space delimited tabular file that looks like this: >NODE 28 length
I have some tabular data, when the label has some specific value I need
We have recently compared the respective file sizes of the same tabular data (think
I have some tabular data which has a lot of fields in it, and
I have a tabular file with a column that is recurrent example toto tata
I have a text file containing tabular data. What I need to do is
I have a PDF file containing some tabular data. http://dl.dropbox.com/u/44235928/sample_rotate-0.pdf I have to extract
I have a huge pdf file (20 mb/800 pages) which contains some information. It

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.