Answer the question
In order to leave comments, you need to log in
Compare two text files, excluding duplicate lines
The task will probably seem strange, but I hope that someone can help.
And so, there are two *.txt files
. The first is "base.txt":
01
02
02
03
04
05
04
08
15
16
23
42
01
02
03
05
Answer the question
In order to leave comments, you need to log in
Well, you're unlikely to find such a plugin. The task is quite specific. But it’s very easy to make one-liners for this case:
grep -vf exceptions.txt base.txt | sort -u
grep -vf exceptions.txt base.txt | sort -u > base.tmp ; mv base.tmp base.txt
A bike:
#!/usr/bin/perl
use strict;
use warnings;
die "Usage: $0 filtered.txt filter.txt\n" if @ARGV != 2;
my %filter;
open F, $ARGV[1] or die "Cannot open $ARGV[1]: $!\n";
while(<F>) {
chomp;
$filter{$_} = 1;
}
close F;
open F, $ARGV[0] or die "Cannot open $ARGV[0]: $!\n";
while(<F>) {
chomp;
print "$_\n" unless $filter{$_};
$filter{$_} = 1;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question