Operating System - HP-UX
1826382 Members
4216 Online
109692 Solutions
New Discussion

Question about vi and replacing text

 
SOLVED
Go to solution
Frederic Sevestre
Honored Contributor

Question about vi and replacing text

Hi,
In a file, I need to replace a lot of couples of lines like :

option status =
enable

by only one line like :

option status = enable

Is it possible using the substitute ? What is the easyest way to proceed ?
Thanks

Crime doesn't pay...does that mean that my job is a crime ?
4 REPLIES 4
Marco Paganini
Respected Contributor
Solution

Re: Question about vi and replacing text

Hello,

If you're sure that all lines come like:

option status =
something

You can use in vi:

:g/^option status =.*$/j

That ought to do the trick for you.

Regards,
Paga
Keeping alive, until I die.
Justo Exposito
Esteemed Contributor

Re: Question about vi and replacing text

Hi Frederic,

you can do it with sed command, try this in the prompt:
"sed -e '/^enable/d' -e 's/option status =/option status = enable/' filename > filenamenew"

hope this help

Justo.
Help is a Beatiful word
Frederic Sevestre
Honored Contributor

Re: Question about vi and replacing text

Thanks, it work fine with Marco's sugest.
Crime doesn't pay...does that mean that my job is a crime ?
Deepak Extross
Honored Contributor

Re: Question about vi and replacing text

An easy way, without even opening the file in vi:
cat | paste - - >