vi editor search and replace question

vi editor search and replace question

Post by Trent Rive » Tue, 09 Mar 2004 12:43:42



Usig vi as my editor, i want to search for all occurences a text
string and in those lines where the text string is found i want to
replace another different string in that line with a new string.

Does anybody know how to do this in vi???

 
 
 

vi editor search and replace question

Post by William Par » Tue, 09 Mar 2004 15:11:12



> Usig vi as my editor, i want to search for all occurences a text
> string and in those lines where the text string is found i want to
> replace another different string in that line with a new string.

> Does anybody know how to do this in vi???

Hint:
    :g/abc/s/xyz/123/

--

Linux solution for data processing and document management.

 
 
 

vi editor search and replace question

Post by Dave Beye » Tue, 09 Mar 2004 14:42:09



Quote:> Using vi as my editor, i want to search for all occurences a text
> string and in those lines where the text string is found i want to
> replace another different string in that line with a new string.

> Does anybody know how to do this in vi???

        You will find helpful answers to this and other editor,
vi related questions in comp.editors.  There you will also find
Frequently Asked Questions (FAQs) that address similar issues.

        Open the file using vi

        type a : to put you in ex mode -- you will see a : at
        the very left-bottom of the screen.

        type

            g/search_string/s/old_string/new_string/g

            g - in every line

            /search_string/ - search for this string

            s - substitute

            /old_string/ - string to replace, may be the same or
                           different from search string

            /new_string/ - replacement string, new text

            g - do this for all occurrances of old_string in line

 
 
 

vi editor search and replace question

Post by rakesh shar » Tue, 09 Mar 2004 16:32:06



> Usig vi as my editor, i want to search for all occurences a text
> string and in those lines where the text string is found i want to
> replace another different string in that line with a new string.

> Does anybody know how to do this in vi???

at the : prompt in vi do this

    :g/string1/s/string2/new_string/

 
 
 

vi editor search and replace question

Post by ajay » Tue, 09 Mar 2004 18:31:55


:s/old_string/new_string/g

isn't simple and nice ?



> > Using vi as my editor, i want to search for all occurences a text
> > string and in those lines where the text string is found i want to
> > replace another different string in that line with a new string.

> > Does anybody know how to do this in vi???

>         You will find helpful answers to this and other editor,
> vi related questions in comp.editors.  There you will also find
> Frequently Asked Questions (FAQs) that address similar issues.

>         Open the file using vi

>         type a : to put you in ex mode -- you will see a : at
>         the very left-bottom of the screen.

>         type

>             g/search_string/s/old_string/new_string/g

>             g - in every line

>             /search_string/ - search for this string

>             s - substitute

>             /old_string/ - string to replace, may be the same or
>                            different from search string

>             /new_string/ - replacement string, new text

>             g - do this for all occurrances of old_string in line

 
 
 

vi editor search and replace question

Post by Birger Blix » Sat, 13 Mar 2004 03:38:51



Quote:> :s/old_string/new_string/g

> isn't simple and nice ?

But wrong, and top posted.

/bb

 
 
 

1. newbie question on search and replace using vi editor

I am trying to replace the word error
with MyError in the vi editor

so the word error appears
like this monerror
or stuerror

wold I replace doing this
s/\<error>/MyError/g

with g being for Global.

I tried doing this and the document
was not updated from what I could see.

Thanks

Kevin

--
       remove the words REMOVETHIS to reply  me
00
<
__/    Kevin D.

2. Tekram's SCSI Card Linux Supported

3. vi search/replace question...

4. Sound setup?

5. RH 5 & IPX

6. Global search and replace using vi -c?

7. Setting MAC address at boot

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

9. vi search/replace: Want >1 line context

10. How to search and replace a decimal in vi?

11. Vi search and replace don't work

12. Searching/replacing / with vi