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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:00:19+00:00 2026-06-17T02:00:19+00:00

how to parse a file based on data from another file using awk. i

  • 0

how to parse a file based on data from another file using awk.

i made a script:

BEGIN{ FS="\t" ; OFS="\t"

while((getline<"headfpkm")>0) {
        ++a
        id[a]=$1
        fpkm[a]=$2
        print id[a],fpkm[a]
        }
lastid=id[a]
print lastid
close("headfpkm")
}

/$lastid/{
        print $2,$3,$5,$7,$8,$14,fpkm[a]
        a--
        lastid=id[a]
}
END{ print "total lines=",FNR,"\n\nfile 1 index: ",a}

when i run it :

/$ awk -f testawk.awk file2

it runs the BEGIN section properly but doesnt give any output.

NM_000014       5.04503
NM_000015       0.586677
NM_000016       1.138332278
NM_000017       0.64386
NM_000018       3.61746
NM_000019       2.8793
NM_000020       10.846
NM_000021       0.685098
NM_000022       46388.6
NM_000026       0.257471
NM_000026
total lines=    10

file 1 index:   10

Is anything wrong with the searching section??

file 2 looks like this:

34      ACADM   NM_000016       9606    hsa-miR-3148    3       80      87      0.003   -0.016  -0.094  0.082   0.112   -0.160  97
34      ACADM   NM_000016       9606    hsa-miR-3163    1       623     629     0.001   -0.022  -0.020  0.065   0.125   -0.01   57
35      ACADS   NM_000017       9606    hsa-miR-3921    3       68      75      0.013   0.192   -0.097  0.031   -0.039  -0.147  82
35      ACADS   NM_000017       9606    hsa-miR-4303    2       67      73      0.012   0.150   -0.052  0.013   -0.039  -0.036  31
35      ACADS   NM_000017       9606    hsa-miR-4653-5p 3       68      75      0.003   0.192   -0.097  0.031   -0.039  -0.157  84
37      ACADVL  NM_000018       9606    hsa-miR-124     2       31      37      0.003   0.023   -0.057  0.012   -0.032  -0.171  76
37      ACADVL  NM_000018       9606    hsa-miR-1827    2       135     141     -0.007  -0.043  -0.058  0.039   -0.069  -0.258  91
37      ACADVL  NM_000018       9606    hsa-miR-2682    2       134     140     0.003   -0.014  -0.058  0.004   -0.047  -0.232  87
37      ACADVL  NM_000018       9606    hsa-miR-449c    2       134     140     -0.035  -0.014  -0.058  0.004   -0.047  -0.270  92
37      ACADVL  NM_000018       9606    hsa-miR-506     2       31      37      -0.016  0.023   -0.057  0.012   -0.032  -0.190  80
  • 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-17T02:00:20+00:00Added an answer on June 17, 2026 at 2:00 am

    This is going to be a bit of guess, because I’m not 100% sure as to what you’re trying to accomplish. The better way to solve your problem, would be to do something like this:

    BEGIN {
        FS=OFS="\t"
    }
    
    FNR==NR {
        c++
    
        a[$1]=$2
        next
    }
    
    $3 in a {
        print $2,$3,$5,$7,$8,$14,a[$3]
    }
    
    END {
        printf "total lines=%s\n\nfile 1 index: %s\n", FNR, c
    }
    

    Run like:

    awk -f script.awk headfpkm file2
    

    Results:

    ACADM   NM_000016  hsa-miR-3148     80   87   -0.160  1.138332278
    ACADM   NM_000016  hsa-miR-3163     623  629  -0.01   1.138332278
    ACADS   NM_000017  hsa-miR-3921     68   75   -0.147  0.64386
    ACADS   NM_000017  hsa-miR-4303     67   73   -0.036  0.64386
    ACADS   NM_000017  hsa-miR-4653-5p  68   75   -0.157  0.64386
    ACADVL  NM_000018  hsa-miR-124      31   37   -0.171  3.61746
    ACADVL  NM_000018  hsa-miR-1827     135  141  -0.258  3.61746
    ACADVL  NM_000018  hsa-miR-2682     134  140  -0.232  3.61746
    ACADVL  NM_000018  hsa-miR-449c     134  140  -0.270  3.61746
    ACADVL  NM_000018  hsa-miR-506      31   37   -0.190  3.61746
    total lines=10
    
    file 1 index: 10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to parse a file based on a record layout provided in another
I want to parse data from a log file, pump it into a database,
I'm trying to parse text-based file attachments (txt, doc, etc...). However, I can't seem
I need to parse a file but the data is in a strange format
Need to parse a file for lines of data that start with this pattern
I am parsing an XML file from a URL, from this XML I parse
I have a PHP script that works by calling items from a database based
I'm trying to parse a moderately large XML file (6mb) in php using simpleXML.
I have a flat file of e-mail header data that I'm trying to parse
I have a class that parses in data from a comma delimited text 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.