Monday, April 15, 2024
 Popular · Latest · Hot · Upcoming
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1666  / 2 Years ago, mon, january 10, 2022, 9:38:27

For a simple example say I have list file which has the following contents

cat dog pig
dog hat
clap sing
cat hog
one two three

I then have a 'pattern' file. With the below content


What I would like to happen is a new file is created from the list file but all lines that begin with cat or dog I not copied over.

I have seen a few examples how this can work e.g.

sed '/pattern to match/d' ./infile > ./newfile

From what I have gathered sed can't handle a 'pattern input file'. Is that a similar program to sed that could achieve what I would like to do? If not could a make a program in python program that reads each line from the 'pattern' file and run the sed command against th list file e.g. multiple passes with seds

More From » sed


You can use tell grep to read its patterns from a file - with the -v (invert) switch that should do what you want

fgrep -vf patternfile listfile

From man grep

   -f FILE, --file=FILE
Obtain patterns from FILE, one per line. The empty file
contains zero patterns, and therefore matches nothing. (-f is
specified by POSIX.)

[#27714] Wednesday, January 12, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 121
Total Questions: 108
Total Answers: 107

Location: United States Minor Outlying Island
Member since Sat, May 28, 2022
2 Years ago