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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:02:37+00:00 2026-06-18T02:02:37+00:00

I have the following issue that I’m trying to solve in bash. I have

  • 0

I have the following issue that I’m trying to solve in bash. I have two different files (file1, file2) contaning a list of information like the following:

HWI-1KL104:145:C18ANACXX:5:1101:1168:2164   4   *   0   0   *   *   0   0   GTGCCTGAACTGGATGCATNGACAATGGGGAACATTACATATATAATACAAGGGAAACTCAAACGTTTCCNNNNNCAAGTATTTGACAGNNNNNNNNNNNN   @B@DDFFFHHHHHIHIJIJ#3AFGHHJJJJIIJJIJIIIJJJJJJJGIIJIJJJIJIJJJJIJJI=@EED#####,,5=;ADDFEEDDD############

The string showed represent A SINGLE LINE. Meaning that if I do:

grep "HWI-1KL104:145:C18ANACXX:5:1101:1168:2164" file1

my output is the string above. The HWI-1KL104:145:C18ANACXX:5:1101:1168:2164 represents the ID of my line

You have to imagine millions of lines like this (~8GB of txt file) with different IDs

What I have to do is:

  1. search for those IDs present in file1 that are present in file2

  2. save the matched lines in file2 into a new file containing ONLY the ID + following information:

HWI-1KL104:145:C18ANACXX:5:1101:1196:2120
CCCCTTCTCCAGGGGACCANGTATGTTTCTCTTATGGTCCTCCTTGTTTACTAGCTTCTCTGGCAGTGAGATTGTAGGCTGGTAATCCTTTACTCNNTNNN CCCFFFFFHHHHHJJJJJJ#4CDEEDCDDDDDC######

so, discarding the stuff represented by 4 * 0 0 * * 0 0 (that is fixed in terms of lenght but not in content..meaning that could be 3 * 1 0 * * 0 1 and so on..).

So my file1 represent a sort of “reference” of my IDs that I want to find and save in file2.

It is quite difficult to me to explain. I hope you understand what I would like to do.

I think that a grep should work but I don’t know how to grep just some information within a line and compare to 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-18T02:02:39+00:00Added an answer on June 18, 2026 at 2:02 am

    Could use a for loop

        outputfile="/tmp/something"
        file1=3; file2=4; 
        for ids in $(cat $file1|awk '{print $1}'); 
        do
              #echo working on $id**
              grep $ids $file2|awk '{print $3" "$4" "$5}' >> $outputfile
        done
    

    Above is the same script now expanded and the output sent to a file, so rather than pumping script to a file – you could execute the script and let it handle where it puts the output.

    Sure you can run it on large files, it may just take a while to get going and may take some time to finish, the problem with using this method is that it works and is easy use but may not be as fast as some of the other complex methods suggested.

    You could enable the working on id line to get more verbosity

    additional notes:

    for filesfound in $(pattern=1101; grep $pattern 3*|awk -F":" '{print $1}'); do
     echo "found $filesfound"; 
     grep "newpattern" $filesfound; 
     done;
    
    found 3
    found 33
    

    you could dig further into initial grep like this:

     grep $pattern *|awk -F":" '{print "-- FILE: " $1 " --- ENTIRE_STRING: "$0}'
    -- FILE: 3 --- ENTIRE_STRING: 3:HWI-1KL104:145:C18ANACXX:5:1101:1168:2164   4   *   0   0   *   *   0   0   GTGCCTGAACTGGATGCATNGACAATGGGGAACATTACATATATAATACAAGGGAAACTCAAACGTTTCCNNNNNCAAGTATTTGACAGNNNNNNNNNNNN   @B@DDFFFHHHHHIHIJIJ#3AFGHHJJJJIIJJIJIIIJJJJJJJGIIJIJJJIJIJJJJIJJI=@EED#####,,5=;ADDFEEDDD############
    -- FILE: 33 --- ENTIRE_STRING: 33:HWI-1KL104:145:C18ANACXX:5:1101:1168:2164   4   *   0   0   *   *   0   0   GTGCCTGAACTGGATGCATNGACAATGGGGAACATTACATATATAATACAAGGGAAACTCAAACGTTTCCNNNNNCAAGTATTTGACAGNNNNNNNNNNNN   @B@DDFFFHHHHHIHIJIJ#3AFGHHJJJJIIJJIJIIIJJJJJJJGIIJIJJJIJIJJJJIJJI=@EED#####,,5=;ADDFEEDDD############
    

    This is now returning file name|all string then looking for pattern and returning everything after the pattern – you can customise it by adding more awk statements on the end of the line

    pattern=1101; grep $pattern *|awk -F":" '{print $1"|"$0}'|awk -F"$pattern" '{print $2}'
    :1168:2164   4   *   0   0   *   *   0   0   GTGCCTGAACTGGATGCATNGACAATGGGGAACATTACATATATAATACAAGGGAAACTCAAACGTTTCCNNNNNCAAGTATTTGACAGNNNNNNNNNNNN   @B@DDFFFHHHHHIHIJIJ#3AFGHHJJJJIIJJIJIIIJJJJJJJGIIJIJJJIJIJJJJIJJI=@EED#####,,5=;ADDFEEDDD############
    :1168:2164   4   *   0   0   *   *   0   0   GTGCCTGAACTGGATGCATNGACAATGGGGAACATTACATATATAATACAAGGGAAACTCAAACGTTTCCNNNNNCAAGTATTTGACAGNNNNNNNNNNNN   @B@DDFFFHHHHHIHIJIJ#3AFGHHJJJJIIJJIJIIIJJJJJJJGIIJIJJJIJIJJJJIJJI=@EED#####,,5=;ADDFEEDDD############
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following issue is that i have 3 calendar controls (different ID) in a
I have the following issue. I have two classes that manipulate information but they
I have the following issue to solve. I have an IQueryable list of Invoices,
I have the following issue: a list item that once clicked, a div slides
I have the following issue with a UTF8 files structured as following: FIELD1§FIELD2§FIELD3§FIELD4 Looking
I have the following issue: A java object contains two arrays of core datastore
I am using Django 1.3 and have the following issue: In the Admin list
Im trying to query the Netflix OData feed. I have the following query that
I'm having an issue that I can't seem to solve myself. I have the
OK guys so the issue is that I have following code: HttpWebRequest req; HttpWebResponse

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.