Solved

vi replace " " with return

Posted on 2001-06-26
8
249 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
8 Comments
 

Expert Comment

by:vinayaca
Comment Utility
try this command in VI editor (Command mode)

:s/" "/^M/g

0
 
LVL 5

Expert Comment

by:marecs
Comment Utility
:%s/ /\n/g
0
 

Author Comment

by:Stoke
Comment Utility
Neither option works
0
 
LVL 5

Expert Comment

by:marecs
Comment Utility
What OS?

By not working do you mean nothing happened or the wrong thing happened?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

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

Accepted Solution

by:
marecs earned 50 total points
Comment Utility
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
Comment Utility
Brilliant. That's exactly what I wanted.
0
 

Expert Comment

by:tomasino
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
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…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now