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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:30:18+00:00 2026-06-06T03:30:18+00:00

Some days ago I asked a question about tagging differencies in 2 text files,

  • 0

Some days ago I asked a question about tagging differencies in 2 text files, and was answered quickly.

now I have a rather similar question but a bit more complicated.
I have 2 pair of files by the following characteristics:
pair1: (File1.txt , File2.txt)
pair2: (File3.txt , File4.txt)

There is a line by line correspondence between each files in these pairs. say that File1.txt and File3.txt are some English words, and File2.txt and File4.txt are their Arabic and French translations respectively. In addition, File1.txt and File3.txt are very similar (and in some cases the same).


    File1.txt       File2.txt
    EnWord1         ArTrans1
    EnWord2         ArTrans2
    EnWord3         ArTrans3
    Enword4         ArTrans4

    File3.txt       File4.txt
    EnWord1         FrTrans1
    EnWord3         FrTrans3
    Enword4         FrTrans4
    Enword5         FrTrans5

Now what I want to do is to compare English sides of these pairs, find the common words that appear in both files (EnWord1,EnWord3, and EnWord4) and filter out their corresponding translations.
In short, I can say that using two bilingual English-Arabic and English French dictionaries, I am trying to build a 3-lingual English-Arabic-French dictionary.
How it is possible?

I have to add that since there are many such pairs (the dictionaries are stored in different files, each file contains a part of the words, and by some reasons it is not possible to merge files and then process them) the speed of the code is very important and I am looking for a fast way to do this.

Finally, please give me some points (or even possible the complete code) to do this in Perl.

Best regards,
Hakim

  • 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-06T03:30:19+00:00Added an answer on June 6, 2026 at 3:30 am

    I assume that the order you would like to maintain follows File1.txt. The following perl should accomplish what your looking for:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    my @pair1 = `paste -d ":" $ARGV[0] $ARGV[1]`;
    my @pair2 = `paste -d ":" $ARGV[2] $ARGV[3]`;
    
    my @pairs = (@pair1, @pair2);
    my (%seen, @dups);
    
    foreach (@pairs)
    {
      my $word = (split ":", $_)[0];
      push @dups, $word if $seen{$word}++;
    }
    
    open (FILE0, ">", "NEW_File0.txt") or die;
    open (FILE1, ">", "NEW_File1.txt") or die;
    open (FILE2, ">", "NEW_File2.txt") or die;
    
    foreach my $duplicate (@dups)
    {
      print FILE0 "$duplicate\n";
    
      foreach (@pair1) { print FILE1 ((split ":", $_)[1]) if $_ =~ /^$duplicate:/; }
      foreach (@pair2) { print FILE2 ((split ":", $_)[1]) if $_ =~ /^$duplicate:/; }
    }
    
    close FILE0;
    close FILE1;
    close FILE2;
    

    Run like this:

    ./script.pl File1.txt File2.txt File3.txt File4.txt
    

    grep "" NEW_File* results:

    NEW_File0.txt:EnWord1
    NEW_File0.txt:EnWord3
    NEW_File0.txt:EnWord4
    NEW_File1.txt:ArTrans1
    NEW_File1.txt:ArTrans3
    NEW_File1.txt:ArTrans4
    NEW_File2.txt:FrTrans1
    NEW_File2.txt:FrTrans2
    NEW_File2.txt:FrTrans3
    

    May not be the most efficient way to do things, but should give you somewhere to start at least. HTH.

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

Sidebar

Related Questions

Some days ago I asked a question about my problem and I was advised
I posted some days ago this question: How to intersect multiple polygons? . Now
Guys I've asked few days ago a question and didn't have really time to
so I asked here few days ago about C# and its principles. Now, if
few days ago I asked here about implementing USB. Now, If I may, would
I've asked the same question some days ago, but there I wanted to solve
A few days ago I has asked a question on SO about helping me
I've asked a question here couple days ago, about how to avoid a function
A few days ago I asked a question about returning select fields from a
I asked a question about the undefined value in javascript a few days ago.

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.