[PLUG] how to create a comma-delimited list?

Michael Rasmussen rasmussenm at columbiafunds.com
Mon Jul 15 21:18:08 UTC 2002


> From: Matt Alexander [mailto:m at netpro.to]
> 
> I have a list of items like this:
> 
> bob
> sam
> joe
> mark
> sally
> marge
> 
> And I'd like to convert it to this:
> 
> bob,sam,joe,mark,sally,marge
> 
> Is there a way to do this within vi?

Assuming that the list is not the only thing in your file and you eyeball
the number of lines involved you can:

(with cursor on the line with bob)
5Js/ /, /g

or if you'd rather not guess:

:set nu
[ see what the line number is for first and last list item]
:1,5j #substitute real line numbers
:s/ /, /g

^^ Though it breaks on items with embedded spaces so perhaps you'd rather:
:1,5s/$/,/
:1,5j

  
There's a couple of vi-isms to do what you want.

I expect Heinlein will weigh in with a more powerful method.

--  
  Michael Rasmussen - Network Engineer, Columbia Management
  voice:  971-925-6723  cell:  503-807-1447  rasmussenm at columbiafunds.com
  <mailto:rasmussenm at columbiafunds.com> http://www.columbiafunds.com

NOTICE:  This communication may contain confidential or other privileged information.  If you are not the intended recipient, or believe that you have received this communication in error, please do not print, copy, retransmit, disseminate, or otherwise use the information.  Also, please indicate to the sender that you have received this email in error, and delete the copy you received.  Any communication that does not relate to official Columbia business is that of the sender and is neither given nor endorsed by Columbia.  Thank you.






More information about the PLUG mailing list