Skip to main content
deleted 3 characters in body
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k

You could do it with awk like:

awk '
  NR == FNR {w[$0]="";w[$0]; next}
  {for (i in w) if (index($0,i)) delete w[i]}
  END {for (i in w) print i}' file1.txt file2.txt

By using index, we're looking for substrings rather than matching regular expressions.

Because we delete the word from the array as soon as we find a match, we avoid unnecessary searches.

You could do it with awk like:

awk '
  NR == FNR {w[$0]=""; next}
  {for (i in w) if (index($0,i)) delete w[i]}
  END {for (i in w) print i}' file1.txt file2.txt

By using index, we're looking for substrings rather than matching regular expressions.

Because we delete the word from the array as soon as we find a match, we avoid unnecessary searches.

You could do it with awk like:

awk '
  NR == FNR {w[$0]; next}
  {for (i in w) if (index($0,i)) delete w[i]}
  END {for (i in w) print i}' file1.txt file2.txt

By using index, we're looking for substrings rather than matching regular expressions.

Because we delete the word from the array as soon as we find a match, we avoid unnecessary searches.

Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k

You could do it with awk like:

awk '
  NR == FNR {w[$0]=""; next}
  {for (i in w) if (index($0,i)) delete w[i]}
  END {for (i in w) print i}' file1.txt file2.txt

By using index, we're looking for substrings rather than matching regular expressions.

Because we delete the word from the array as soon as we find a match, we avoid unnecessary searches.