• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple question  RSS feed

 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after I upload a text file to unix,
there are some unnecessary double space
like
PETER{SPACE}{SPACE}23
JONH{SPACE}{SPACE}24
MARY{SPACE}{SPACE}12
BEN{SPACE}{SPACE}8
I want to have single space instead.
Anyone can teach me either use emacs, or vi or any other way to "replace all" for the double space?
Thanks so much. =)
[ September 16, 2003: Message edited by: Michael Ernest ]
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From within vi, in command mode you can write

to perform a global replacement on every two spaces to one space.
[ September 16, 2003: Message edited by: Michael Ernest ]
 
Tim Holloway
Saloon Keeper
Posts: 18793
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vi? All you really need for that is sed:
sed -e "s/ +/ /" <badfile >goodfile
That's for multiple spaces (2 or more to convert to a single space) and only the first time it happens on each line. Other variations are also pretty easy.
Using sed, which is non-interactive, you can automate the process.
[ September 17, 2003: Message edited by: Tim Holloway ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!