editor query

Dave Sherman dave at utcsrgv.UUCP
Tue Nov 1 03:11:02 AEST 1983


hcr!doug asks how to get an editor to delete every line containing
A except for those which also contain B.

ed will do it:

g/B/s/A/ZZZZZ/g
g/A/d
g/ZZZZZ/s//A/g

Presto.
It's a little ugly, but it works, and quickly too.
Pick your favourite string for ZZZZZ. It should of course be
something that doesn't occur elsewhere in the file, but unless
you're dealing with random ASCII text, that's not hard to find.

If you have qed and need this often enough, it can easily be
automated into a string register or buffer.

Dave Sherman
Toronto
-- 
 {allegra,cornell,decvax,ihnp4,linus,utzoo}!utcsrgv!dave



More information about the Comp.unix mailing list