Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vi replace " " with return

Posted on 2001-06-26
8
Medium Priority
?
278 Views
Last Modified: 2010-04-21
I need to remove every space " " in a text file with a carrage return so that every word appears as a different line on the text.
0
Comment
Question by:Stoke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 

Expert Comment

by:vinayaca
ID: 6227116
try this command in VI editor (Command mode)

:s/" "/^M/g

0
 
LVL 5

Expert Comment

by:marecs
ID: 6227459
:%s/ /\n/g
0
 

Author Comment

by:Stoke
ID: 6227563
Neither option works
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 5

Expert Comment

by:marecs
ID: 6227609
What OS?

By not working do you mean nothing happened or the wrong thing happened?
0
 

Author Comment

by:Stoke
ID: 6227639
Red hat 7.1
:%s/ /\n/g returns ^@ instead of the spaces, so something happens.
0
 
LVL 5

Accepted Solution

by:
marecs earned 200 total points
ID: 6227892
This is cheating a bit, but it works. I think the problem is that vi would lose its sence of line numbers if it allowed something to be replaced by a newline. It worked on vim under Windows though!

:%!tr " " "\n"

It actually makes use of the external program tr
0
 

Author Comment

by:Stoke
ID: 6227993
Brilliant. That's exactly what I wanted.
0
 

Expert Comment

by:tomasino
ID: 8744280
it sounds like you were running gvim for windows if it displays ^@.  if you don't have the external program tr, you can still use the internal sed commands in vi on a windows machine by doing this:

:s/\ /\r/g

the \r is the newline character for PC.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question