[PLUG] To the VI Question

Shannon C. Dealy dealy at deatech.com
Tue Jul 16 01:45:07 UTC 2002


On Mon, 15 Jul 2002, Matt Alexander wrote:

> OK, here's the contents of a text file after the od -c is run on it:
>
> 0000000   b   o   b  \n   s   a   m  \n   j   o   e  \n   m   a   r   k
> 0000020  \n   s   a   l   l   y  \n   m   a   r   g   e  \n
> 0000035
>
> So there are clearly newline characters.  But...  the :%s/\n/,/ doesn't
> work.  SoooooOOOOooOOoOOoooo...  Any guesses why?  This is a default

I can give a good guess, though I'm really rusty in vi, so I can't say if
this is the case for vi.  Many editors (particularly older ones), are very
line oriented and don't actually even keep the newline in their memory
buffers (so it can't actually match on a newline character because it
isn't there).  Some of these editors do not allow for the concept of a
pattern that spans multiple lines (which any thing with a newline in it
would be), and for many of those that do, they use a special character in
regular expressions such as "$" to represent the concept of "end of line"
or newline.  In all of these editors that I can recall using, doing what
you want was possible, but for at least some of them it might require a
multiple stage process (or creation of a macro), so that you would first
do a search/insert to add your comma to the end of each line, then
perform some kind of "join" to add the next line to the current line.

FWIW.

Shannon C. Dealy      |               DeaTech Research Inc.
dealy at deatech.com     |          - Custom Software Development -
                      |    Embedded Systems, Real-time, Device Drivers
Phone: (800) 467-5820 | Networking, Scientific & Engineering Applications
   or: (541) 451-5177 |                  www.deatech.com





More information about the PLUG mailing list