[TAG] Filters
Ben Okopnik
ben at callahans.org
Sat Apr 17 09:33:10 MSD 2004
On Sat, Apr 17, 2004 at 12:01:12AM +0100, Jimmy O'Regan wrote:
> During my 6 months without 'net access I read quite a lot of books,
> including Trainspotting, and thought it'd be fun to write a filter.
>
> ===== CUT HERE: trainspotting.sed.txt =====
> s/ of / ay /g
> s/ off/ oaf/g
> s/ I / ah /g
Nice. However, you should run a filter over your filters:
sed 's#/ #/\\b#1;s# /#\\b/#1;s/ //g' trainspotting.sed.txt
or something similar, anyway. :) The reason is that (for, e.g., the
first expression) an 'of' at the beginning or the end of a line will be
ignored - there's no space before it at BOL, and none after it at EOL.
'\b' is a word boundary, which will do the right thing.
* Ben Okopnik * okopnik.freeshell.org * Technical Editor, Linux Gazette *
-=-=-=-=-=o0o=-=-=-=-= <http://linuxgazette.net/> =-=-=-=-=o0o=-=-=-=-=-
More information about the TAG
mailing list