PDA

View Full Version : [all variants] VI Editor Question - Soewhat Complex



ecrossahoo
November 20th, 2008, 07:53 PM
Hi Forum,

I have a "challenge" I have not been able to solve. I have a file that contains the following

host1.domain.com
beth
albert
vanessa
julie
host2.domain.com
robert
jake
clare
lisa


I would like to add a newline above every line that contains *.domain.com. So the resulting file would like like:

host1.domain.com
beth
albert
vanessa
julie

host2.domain.com
robert
jake
clare
lisa


Can someone assist with a little search/replace magic?

](*,)

Thank You.

olejorgen
November 20th, 2008, 08:24 PM
:%g/.*domain.com/normal O

ecrossahoo
November 20th, 2008, 11:03 PM
Thank you olejorgen.

So "/normal/" will keep in tact the argument in which you intend to mainuplate, then perform the following vi COMMAND-MODE command?

Thanks again for your code.

olejorgen
November 20th, 2008, 11:52 PM
No problem, and yes. (I think you could do something like :%s/(<pattern>)/\n\1 too, but :s and multilines have always caused me headaches)
PS:

:help :g
:help :normal