So, this issue is driving me nuts! I was hoping to get a lending hand here...
I have 2 files:
file1.txt contains:
this is example1
this is example2
this is example3
this is example4
this is example5
file2.txt contains:
example3
example5
Basically, I need a script or command to generate a new file which contains only the lines that DON'T exist on file2.txt, ideally, the resulting file would look like this:
fileX.txt:
this is example1
this is example2
this is example4
I really appreciate your help, I can't seem to figure this one out..
Thanks a lot!
Dave
you can try something like this:)
grep -v -f file2.txt file1.txt
I thought about that, but it takes forever... the files that I'm working with are quite large.
Is there a better way to accomplish this?
Thanks again!
Dave
#! /usr/bin/perl
open FILE, "/path/to/file1.txt" or die "can't open file: $!\n";
while (<FILE>) {
chomp;
push (@array_one, $_);
}
open FILE, "/path/to/file2.txt" or die "can't open file: $!\n";
while (<FILE>) {
chomp;
push (@array_two, $_);
}
my @C = grep { my $x = $_; not grep { $x =~ /\Q$_/i } @array_two } @array_one;
foreach $C (@C) {
print "$C\n";
}
you can use the below:-
nawk 'FILENAME=="file2" {a[$1]=$1 }
FILENAME=="file1" { if ( ! a[$3] ) { print $0} }
' file2 file1