Operating System - HP-UX
1838711 Members
4773 Online
110128 Solutions
New Discussion

vi/ex delete with multiple pattern searches in ex same command

 
SOLVED
Go to solution
Jack C. Mahaffey
Super Advisor

vi/ex delete with multiple pattern searches in ex same command

vi/ex only please.

I want to be able to delete some rows from file that must meet two pattern searches.

example: Delete all rows that contain patterns "Printer 12" and "autowrap"

jack..
4 REPLIES 4
Rob_132
Regular Advisor

Re: vi/ex delete with multiple pattern searches in ex same command

I don't believe this is possible in vi - don't know about ex.

Of course, if you are willing to permit shell, then:


egrep -v "Printer 12|autowrap" file > newfile

where "file" is the original, and "newfile" is the output.

Rob
Rodney Hills
Honored Contributor

Re: vi/ex delete with multiple pattern searches in ex same command

You could do the following if autowrap follows Printer 12-

:set magic
:g/Printer 12.*autowrap/d

HTH

-- Rod Hills
There be dragons...
aparna challagulla
Valued Contributor
Solution

Re: vi/ex delete with multiple pattern searches in ex same command

hi jack,


:/printer 1 2/;/autowrap/d

this will work if pattern 1 is followd by pattern2

HTH
aparna

If you don't have time to do it right you must have time to do it over
aparna challagulla
Valued Contributor

Re: vi/ex delete with multiple pattern searches in ex same command

hi jack,

my previous answer will delete all the lines in between the first and last match. oops sorry!!!!

i think the best way to do this is using Rod's answer.

to delete all rows containing patterns "printer 1 2" and "autowrap"

:set magic
:g/Printer 1 2.*autowrap/d
:g/autowrap.*Printer 1 2/d

HTH
aparna
If you don't have time to do it right you must have time to do it over