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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:54:13+00:00 2026-06-06T14:54:13+00:00

I have 4 files and would like to know elements which are non overlapping

  • 0

I have 4 files and would like to know elements which are non overlapping (per file) compared to the elements in other files.

File A

Vincy
ruby
rome

File B

Vincy
rome
Peter

File C

Vincy
Paul
alex

File D

Vincy
rocky
Willy

Any suggestion for one liner in perl, python, shell, bash. The expected output is:

File A: ruby, File B: Peter, File C: Paul, Alex File D: rocky, Willy.

  • 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-06T14:54:15+00:00Added an answer on June 6, 2026 at 2:54 pm

    Edit after question clarified: Unique elements across all files, and the file in which it occurs:

    cat File_A File_B File_C File_D |sort | uniq -u | while read line ; do file=`grep -l $line File*` ; echo "$file $line" ; done
    

    Edit:

    perly way of doing it, will be faster if the files are large:

    #!/usr/bin/perl
    
    use strict;
    use autodie;
    
    my $wordHash ;
    
    foreach my $arg(@ARGV){
        open(my $fh, "<", $arg);
        while(<$fh>){
            chomp;
            $wordHash->{$_}->[0] ++;
            push(@{$wordHash->{$_}->[1]}, $arg);
        }
    }
    
    for my $word ( keys %$wordHash ){
        if($wordHash->{$word}->[0] eq 1){
            print $wordHash->{$_}->[1]->[0] . ": $word\n"
        }
    }
    

    execute as:
    myscript.pl filea fileb filec … filezz

    stuff from before clarification:
    Easy enough with shell commands. Non repeating elements across all files

    cat File_A File_B File_C File_D |sort | uniq -u
    

    Unique elements across all files

    cat File_A File_B File_C File_D |sort | uniq
    

    Unique elements per file
    (edit thanks to @Dennis Williamson)

    for line in File* ; do echo "working on $line" ; sort $line | uniq ; done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a html file that has invoice details I would like to know
I have files served like so: AJAX request handler -> Include file I would
I would like to know how to remove all elements from an xml file
I would like to have multiple files in a folder with are managed by
I would like to rename files numbering: I have a files with '???' format
I have DirectX .x files and I would like to display the model in
I have 50 php files that I would like to run simultaneously from the
I have some files in my SVN repository that I would like to have
I have 2 files, somefile.h and somefile.m . I would like to combine them
Essentially I would like to have a messages.properties files external to the jar files

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.