Article View: comp.unix.shell
Article #1165Re: changing a ! to a \nC where \n is a newline
From: Norman Joseph
Date: Tue, 18 Sep 1990 13:11
Date: Tue, 18 Sep 1990 13:11
35 lines
2014 bytes
2014 bytes
In <5015@alpha.cam.nist.gov> coleman@cam.nist.gov (Sean Sheridan Coleman X5672) writes:
>I am trying to use the global substitution power in vi to
>replace every occurrence of ! with a newline and a C (\nC)
Try this:
:%s/!/^MC/g
Interpretation: `:' - command mode; `%' - for all lines in the file;
`s/!/' - substitute for every bang; `^MC' - a control-M (carriage return)
and the letter C; `/g' - at every occurence in the line. Now, here's
the trick -- to enter a literal carriage return (^M) you must precede it
with vi's escape character, ^V.
>How about the reverse, replace a newline with a character?
Use the regular expression meta-charater for end-of-line, $. Assuming you
want this on all the lines of the file:
:%s/$/<insert your character here>/ e.g. :%s/$/!/
Note: This does not -remove- the newlines from your file; it only allows
you to insert a string -before- the newline. To actually filter out the
newlines you may have to write your own filter and pipe your file through
it (depending on what you want to do, check the man page for tr(1) first).
The sequence for "straining" your file's contents through a filter is:
:%!<insert filter command line here> e.g. :%!sort -rn
--
Norm Joseph - (amanue!oglvee!norm) cgh!amanue!oglvee!norm@dsi.com, or
Oglevee Computer Systems, Inc. ditka!oglvee!norm@daver.bungi.com
---<*>---
"Shucking Usenet oysters in pursuit of a pearl." -- Bill Kennedy
Technical Details
Message-ID:
<602@oglvee.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!tut.cis.ohio-state.edu!pt.cs.cmu.edu!dsl.pitt.edu!pitt!amanue!oglvee!normReferences:
<5015@alpha.cam.nist.gov>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!tut.cis.ohio-state.edu!pt.cs.cmu.edu!dsl.pitt.edu!pitt!amanue!oglvee!norm From: norm@oglvee.UUCP (Norman Joseph) Newsgroups: comp.unix.shell Subject: Re: changing a ! to a \nC where \n is a newline Keywords: vi Message-ID: <602@oglvee.UUCP> Date: 18 Sep 90 13:11:34 GMT References: <5015@alpha.cam.nist.gov> Organization: Oglevee Computer Systems, Connellsville, Pa Lines: 35