LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   vi editor (https://www.linuxquestions.org/questions/linux-newbie-8/vi-editor-755790/)

sabahh 09-16-2009 11:57 PM

vi editor
 
How do i delete a specific string in vi? Suppose i want to delete only the instance "ing" occuring in a file through vi , how could i do this??

vinaytp 09-17-2009 12:06 AM

Quote:

Originally Posted by sabahh (Post 3686365)
How do i delete a specific string in vi? Suppose i want to delete only the instance "ing" occuring in a file through vi , how could i do this??

Not sure whether it is possible through vi, but you can very well do this through command prompt

Have a backup of the file and
use the following command

cat filename | sed 's/ing//g' > filename

If this results in empty file use the commands shown below

sed 's/ing//g' filename > temp
mv temp filename

Hope this helps...

vishesh 09-17-2009 12:19 AM

I think following should do your job
:%s/ing//g
thnks

chrism01 09-17-2009 12:20 AM

vi/vim: bring up the cmd line ie

<esc>:

then

:%s/ing//g

explanation

s/x/y/ = substitute/string_to_find/replacement_string/
% = for all lines
g = for all occurrences

make sure you take a backup first. Also, you can immediately undo using <esc>u


All times are GMT -5. The time now is 07:17 AM.