Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete line with matching pattern from another file?

I want to delete lines in FILE1 contains pattern in FILE2.
How do I do this using shell/bash or Tcl?

For example:

FILE1:

This is ECO_01  
This is ECO_02  
This is ECO_03  
This is ECO_04

FILE2:

ECO_02  
ECO_04  

Output:

This is ECO_01   
This is ECO_03  
like image 660
Bryan Avatar asked Sep 11 '25 16:09

Bryan


1 Answers

most generic solution will be

$ grep -vf file2 file1

note that any substring match on any field will count. If you only restrict to exact match on an exact field (here assumed the last)

$ awk 'NR==FNR{a[$1]; next} !($NF in a)' file2 file1
like image 131
karakfa Avatar answered Sep 13 '25 06:09

karakfa