LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-17-2009, 12:57 AM   #1
sabahh
LQ Newbie
 
Registered: Sep 2009
Posts: 3

Rep: Reputation: 0
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??
 
Old 09-17-2009, 01:06 AM   #2
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Rep: Reputation: 55
Quote:
Originally Posted by sabahh View Post
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...
 
Old 09-17-2009, 01:19 AM   #3
vishesh
Member
 
Registered: Feb 2008
Distribution: Fedora,RHEL,Ubuntu
Posts: 661

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

Last edited by vishesh; 09-17-2009 at 01:48 AM.
 
Old 09-17-2009, 01:20 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux distro / photo editor / music editor of choice ?? expatcanuck Linux - Newbie 1 05-04-2009 06:24 PM
LXer: Open Movie Editor: Linux Video Editor with Plot Twists LXer Syndicated Linux News 0 10-27-2008 10:50 PM
Which Editor? DaftDave Linux - Software 5 05-16-2008 07:50 PM
Vi editor pradeepkoodvalli Linux - General 5 10-27-2006 05:54 PM
best editor Kaninchen Linux - Software 14 07-27-2004 07:52 PM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration