changing a ! to a \nC where \n is a newline

Bob McGowen x4312 dept208 bob at wyse.wyse.com
Thu Sep 20 11:23:06 AEST 1990


In article <5015 at alpha.cam.nist.gov> coleman at 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)
  >
  >I have tried the following things:
  >
  >g/;/s//\\nC/g   places the string \\nC where the ; is not a
  >newline.
  >
  >g/;/s//\nC/g -- places a nC where the ; is.
  >
  >Do you know how to make get vi to put a newline not a \n 
  >when doing the substitution?

You need to go into the full ex mode first by typing an upper case Q.
Then you would enter:

g/;/s//\
C/g

The backslash at the end of the first line escapes the newline immediately
after so the pattern becomes what you want.

  >
  >How about the reverse, replace a newline with a character?
  >

To globally do this is not something I know how to do.  To do it once or
twice, from the visual mode type J which joins the current line and the
line following into one (this replaces the newline with a space).  Then
you could replace the space with the character you want.  Not too
elegent but it works.  If you have to do it often look up :map for
creating a single key command out of the sequence.

  >
  >Sean Coleman
  >NIST
  >coleman at bldrdoc.gov


Bob McGowan  (standard disclaimer, these are my own ...)
Product Support, Wyse Technology, San Jose, CA
..!uunet!wyse!bob
bob at wyse.com



More information about the Comp.unix.shell mailing list