Xref: utzoo comp.unix.misc:686 comp.unix.questions:27404 Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!execu!sequoia!uudell!bigtex!texsun!csccat!dalnet!dlss2!james From: james@dlss2.UUCP (James Cummings) Newsgroups: comp.unix.misc,comp.unix.questions Subject: Re: A question on .exrc while using vi Keywords: exrc vi Message-ID: <125@dlss2.UUCP> Date: 5 Dec 90 18:54:20 GMT References: <5315@graphite20.UUCP> Reply-To: james@dlss2.UUCP (James Cummings) Followup-To: comp.unix.misc Distribution: usa Organization: RedRock Development Lines: 35 In article mju@mudos.ann-arbor.mi.us (Marc Unangst) writes: >joshi@motcid.UUCP (Abhay B. Joshi) writes: >> I have a simple text-file containing the following text (3 lines): >> >> The goal: >> All I am trying to do is replace the 'the's by 'an's. >> That's all. > >Son, vi is the wrong tool for the job. > >ed file <1,$g/the/s//an/g >w >q >Frobozz > Well, I wouldn't say vi is the "wrong tool for the job"! Simply do the following: :%s/the/an/g This is the equivalent of the above ed command...which boils down to a matter of personal taste. The only problem I see with either of these solutions, is that the word "theatre" becomes the word "anatre"....boo-hisss! A more practical solution would be in three steps, like so: :%s/ the / an /g :%s/^the /an /g :%s/ the$/ an/g There is probably a fancier way to do all of this in one swift move but it escapes me for now. Do note the use of spaces and the fact that we are also looking for the 'the's that are at the begining and ending of lines while preserving the integerity of words like "either", "theatre", etc.