How to exclude a substring with a Perl one-liner?

jl66
jl66 used Ask the Experts™
on
Have a file
test.txt
ADC ABC-CBD-XYZ
QRS CBD-123
.....
Have much more similar entries to QRS CBD-123. Want ot exclude the entry ADC ABC-CBD-XYZ with the pattern -XYZ., so the result will be
QRS CBD-123
....
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
perl -e "while(<>) { print if (! /-XYZ/); }" <test.txt
Top Expert 2007
Commented:
perl -ne 'print unless /-XYZ/' file
Top Expert 2009
Commented:
Minor change to what Tintin has if you only want lines when the -XYZ is at the end:
    perl -ne 'print unless /-XYZ$/' test.txt

On windows, you need double quotes:
    perl -ne "print unless /-XYZ$/" test.txt

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial