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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:16:00+00:00 2026-06-14T17:16:00+00:00

Extracting matching lines using perl is known to me but I want the lines

  • 0

Extracting matching lines using perl is known to me but I want the lines from two files which are not matching i.e. they are unique to the file among two text files.

file1:

one|E2027.1|073467|66   ATGCTATGTTTTGCTAAT  
one|E2002.1|073405|649  ATGAAAGCTTTAAAGAAA  
one|E2001.1|734704|201  ATGTTTTCAGGTATTATA  
one|E2025.1|073468|204  ATGAAACAGAAATATATT  
one|E2028.1|073431|578  ATGTTATTTAATTATGGT  
one|E2040.1|073743|862  ATGATTTATCCTAATAAT   

………~2000 such lines

file2:

one|E2027.1|073467|66  
one|E5005.5|000005|005  
one|E2001.1|734704|201  
one|E2025.1|073468|204  
one|E2028.1|073431|578  
one|E2040.1|073743|862    

………~2000 such lines

how to extract the lines not matching using perl or cmd commands?
here e.g. line 2 of file two is unique to file 2…..!!!

Here’s what I have so far

foreach(@2) {
    @org=split('\t',$_);
    chomp($two=$_);
    foreach(@1) {
        if($_=~m/^$two.+/) {
            print OUT1 "$_";
        } else {
            print OUT2 "$_";
        }
    }
}

but else output gives GB of data.

  • 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-14T17:16:01+00:00Added an answer on June 14, 2026 at 5:16 pm

    You have to read in one of the files first. Then you can match against the content of each line of the other file. I used first from List::Util to do that. grep is fine, too, but first stops after it finds the first occurrence, which saves you time with large files.

    use strict;
    use warnings;
    use List::Util qw(first);
    use 5.014;
    
    my $file1 = <<"FILE1";
    one|E2027.1|073467|66\tATGCTATGTTTTGCTAAT
    one|E2002.1|073405|649\tATGAAAGCTTTAAAGAAA
    one|E2001.1|734704|201\tATGTTTTCAGGTATTATA
    one|E2025.1|073468|204\tATGAAACAGAAATATATT
    one|E2028.1|073431|578\tATGTTATTTAATTATGGT
    one|E2040.1|073743|862\tATGATTTATCCTAATAAT
    FILE1
    
    my $file2 = <<"FILE2";
    one|E2027.1|073467|66
    one|E5005.5|000005|005
    one|E2001.1|734704|201
    one|E2025.1|073468|204
    one|E2028.1|073431|578
    one|E2040.1|073743|862
    FILE2
    
    my @file1_content = map { (split(/\t/))[0] } split /\n/, $file1;
    
    foreach my $line (split /\n/, $file2) {
      chomp $line; # we need that because the split above is just a filler
      next if first { $_ eq $line } @file1_content;
      say $line;
    }
    

    I strongly suggest you use strict and warnings in all your programs. They both help you to find small, subtle mistakes. It’s also a good idea to name your variables in a more descriptive way. Arrays named @1 and @2 are very bad. I had trouble understanding which variable did what.

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

Sidebar

Related Questions

I'm looking into extracting all the content from a DTD using Perl, but I'm
I am extracting double data from sqlite3 database. But I want to display it
I am extracting a time stamp from JSON which I want to convert to
I am working on extracting features from avi files using MATLAB. Every time I
I'm struggle extracting necessary data from this json stored inside php variable. Not yet
Extracting data from XML I want to preprocess one before sending it as a
I have just started learning MySQL and am having trouble extracting matching flights from
I am extracting some text from html which is passed as a string. The
I am extracting a string from a database which needs to be parsed into
Extracting data between HTML tags using regular expression I have this example which successfully,

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.