Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
704 views
in Technique[技术] by (71.8m points)

awk - Delete lines based on patterns in another file

I have two files:

input.txt:

Hi 1-12T2EDD
1-13D62L6Hello
1-15SDWAKWazzup
Wow1-18Z3QWY

filter.txt:

1-15SDWAK
1-1VF3XHV

I want to delete lines with matching pattern from filter.txt in input.txt. In SQL understanding, I want to do left outer join input.txt with filter.txt.

output.txt:

Hi1-12T2EDD
1-13D62L6Hello
Wow1-18Z3QWY
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

A simple grep will do this:

$ grep -Fvf filter input
Hi 1-12T2EDD
1-13D62L6Hello
Wow1-18Z3QWY

Options:

  • -F for fixed strings as we don't need regexp matching
  • -v for inverse matching
  • -f for specifing the file containing the strings to (inverse) match.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...