I have a txt file that has a bunch of lines. I used grep to print lines matching pattern 1 to a second file. I want to modify the command to exclude the lines the match pattern 2. So the requirement is
if (match pattern 1) && (! match pattern 2 )
print to csv
Eg:
eat the apple
eat the orange
eat the apple and orange
Pattern 1: apple
Pattern 2: orange
Desired output:
eat the apple
Current output:
eat the apple
eat the apple and the orange
How should I go about it?
Thank you!
I have used the following commands but I either get all lines matching pattern 1 (including the ones matching pattern 2) or nothing at all:
-
awk ‘! /orange/ && /apple/’ input >> output;
result:
eat the apple
eat the apple and the orange -
sed -e “/apple/” | sed -e “/orange/!d” input >> output;
error: extra characters -
grep -i “apple” input >> output;
result:
eat the apple
eat the apple and the orange
I also tried using grep | sed, but also resulted in an error.