VI -global replace

VI -global replace

Post by ========== P7P ========= » Fri, 11 Oct 2002 22:54:31



Can someone remind me how to do a global replace in VI ??

I want to delete all spaces before End of Line character($)

I'm trying things like:

:g s/ $/$/g

Can't quite get the command right.

Thanks all
P7P

 
 
 

VI -global replace

Post by John Gordon,217-352-6511x7418,CEERD-CF- » Fri, 11 Oct 2002 22:57:01



Quote:> Can someone remind me how to do a global replace in VI ??
> I want to delete all spaces before End of Line character($)
> I'm trying things like:
> :g s/ $/$/g
> Can't quite get the command right.

:%s/  *$//

John Gordon
---
"She even named one city after Robert, her ex-boyfriend, just to annoy
me.  I have it in a saved game on my laptop.  Every now and then I boot
it up just to let Robertville starve itself off the map."  -- Tom Chick

 
 
 

VI -global replace

Post by Al Shark » Fri, 11 Oct 2002 23:00:15



Quote:> Can someone remind me how to do a global replace in VI ??

> I want to delete all spaces before End of Line character($)

> I'm trying things like:

>:g s/ $/$/g

> Can't quite get the command right.

Two spaces before the asterisk:

:%s/  *$//

or

:g/  *$/s///

 
 
 

VI -global replace

Post by Tim Hayne » Fri, 11 Oct 2002 23:06:16



Quote:> I want to delete all spaces before End of Line character($)

> I'm trying things like:

> :g s/ $/$/g

> Can't quite get the command right.

:%s/ *$//

(%  : you want to do it to all lines in the file;
  *$: you want any number of spaces - might as well include 0, no harm done;
  //: replace them with nowt.
You don't need a trailling /g as there's only going to be one match per
line, isn't there? ;)

~Tim
--
   15:05:06 up 6 days, 19:52,  8 users,  load average: 0.14, 0.20, 0.18

http://piglet.is.dreaming.org     |Colours ablaze in the evening

 
 
 

VI -global replace

Post by Sayyaparaju Suni » Sat, 12 Oct 2002 01:36:03



> Can someone remind me how to do a global replace in VI ??

> I want to delete all spaces before End of Line character($)

> I'm trying things like:

> :g s/ $/$/g

this expression fetches only 1 space before the end-of-line.
and also, u should not give '$' in the replace string.
so try

:%s/[ ]*$//g

Quote:

> Can't quite get the command right.

> Thanks all
> P7P

 
 
 

VI -global replace

Post by ========== P7P ========= » Sat, 12 Oct 2002 18:09:05




> > Can someone remind me how to do a global replace in VI ??

> > I want to delete all spaces before End of Line character($)

> > I'm trying things like:

> >:g s/ $/$/g

> > Can't quite get the command right.

> Two spaces before the asterisk:

> :%s/  *$//

> or

> :g/  *$/s///

<<Two spaces before the asterisk:>>
One space before asterisk will do won't it ??

P7P

 
 
 

VI -global replace

Post by ========== P7P ========= » Sat, 12 Oct 2002 18:10:29




> > I want to delete all spaces before End of Line character($)

> > I'm trying things like:

> > :g s/ $/$/g

> > Can't quite get the command right.

> :%s/ *$//

> (%  : you want to do it to all lines in the file;
>   *$: you want any number of spaces - might as well include 0, no harm done;
>   //: replace them with nowt.
> You don't need a trailling /g as there's only going to be one match per
> line, isn't there? ;)

> ~Tim
> --
>    15:05:06 up 6 days, 19:52,  8 users,  load average: 0.14, 0.20, 0.18

> http://piglet.is.dreaming.org     |Colours ablaze in the evening

<<might as well include 0, no harm done;>>

What do you mean ??

P7P

 
 
 

VI -global replace

Post by Tim Hayne » Sat, 12 Oct 2002 18:29:05



Quote:>> :%s/ *$//

>> (%  : you want to do it to all lines in the file;
>>   *$: you want any number of spaces - might as well include 0, no harm done;
>>   //: replace them with nowt.
>> You don't need a trailling /g as there's only going to be one match per
>> line, isn't there? ;)
[snip .sig]

> <<might as well include 0, no harm done;>>

> What do you mean ??

* is 0-or-more.

~Tim
--
   10:28:45 up 7 days, 15:15,  9 users,  load average: 0.25, 0.36, 0.37

http://piglet.is.dreaming.org     |the predictability of stupidity.

 
 
 

VI -global replace

Post by Kenny McCorma » Fri, 24 Jan 2003 00:28:46




...

Quote:><<Two spaces before the asterisk:>>
>One space before asterisk will do won't it ??

I usually use 2 so that I get an accurate count of how many instances there
actually were.
 
 
 

1. vi global replace across lines.

Applogies if this is too off topic.

I have some terrible HTML that I need to tidy up, we are talking mainly
huge tables that have cr (0x0A) scattered all over the place. An example
would be.

<TABLE
<
/TD>
<

etc.

If I was to code in perl I would you something like this

s/<TD\n>/\n<TD>/g;

now I want to do this without leaving vi

I tried

%s/<TD\n>/\n<TD>/g

also

%s/<TD^V^M>/<TD>/g

also

%s/<TD^V^J>/<TD>g

nothing worked.

There has to be a way to do this?

Am I just using the wrong control codes?

Or should I just give up and do it in perl.

thanks.

--
TheMartian
AIM: OrigMartian
www.ozetechnology.com
www.marsfirst.org

2. wanted : termcap entry for TeleVideo 905

3. Global search and replace using vi -c?

4. Modem -or- Ethernet

5. global search+replace a newline with J in vi?

6. help:libreadline.so.3

7. global find/replace in vi

8. Compiling Tk-4.1 ?

9. Re :global find/replace in vi

10. global search/replace in vi?

11. Global replace in VI

12. ??? global search&replace ???

13. Global replace of ^M