SED Command – Delete Lines Using Multiple Search Strings

sed

I have a text file, let say test1.txt, I need to remove the line containing dog and date with "29-APR-2015"

Using the below command to accomplish it but it is not deleting the lines.

Where as if i mention just with /DOG/d it is deleting the lines containing DOG.

command file (sedcommands)

/DOG,29-APR-2015/d

test1.txt

DOG          29-APR-2015          
DOG          29-APR-2015          
DOG          30-APR-2015          
CAT          29-APR-2015          
CAT          29-APR-2015          

command

sed -f sedcommands test1.txt > test2.txt

Best Answer

With GNU sed:

sed '/DOG/{/29-APR-2015/d}' test1

This method allows for any order. ie. DOG can either be before or after the date.

Related Question