vi to remove lines in file | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

vi to remove lines in file

UNIX for Dummies Questions & Answers


Tags
vim

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-03-2007
kjbaumann kjbaumann is offline
Registered User
 
Join Date: Jun 2006
Last Activity: 19 August 2008, 1:31 PM EDT
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
vi to remove lines in file

All,

I have a text file with several entries like below:

personname
personname.domain.com

I know there is a way to use vi to remove only the personname.domain.com line. Can someone help? I believe that it involves /s/g/ something...I just can't remember the exact syntax.

Thanks
Sponsored Links
    #2  
Old 10-03-2007
kjbaumann kjbaumann is offline
Registered User
 
Join Date: Jun 2006
Last Activity: 19 August 2008, 1:31 PM EDT
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
I got it:

:g/outdated/d

This command tells vi to do a global search for "outdated" and to delete any line containing that text.

:g/out dated/d

This command tells vi to do a global search for "out dated" and to delete any line containing that text--including the space.
Sponsored Links
    #3  
Old 03-13-2009
uniesh uniesh is offline
Banned
 
Join Date: Mar 2009
Last Activity: 12 April 2010, 6:00 AM EDT
Posts: 16
Thanks: 0
Thanked 1 Time in 1 Post
vi

go to editor mode of vi and type :'g/outdated/d'. this wil delete all lines with the worh outdated.

You can also use :'1,10/outdated/d' to delete lines from 1 to 10 with the word outdated.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How do I remove the duplicate lines in this file? Ernst Shell Programming and Scripting 5 10-25-2011 05:45 PM
remove : lines from file aronmelon Shell Programming and Scripting 5 06-10-2009 11:46 AM
remove lines from file lweegp Shell Programming and Scripting 10 03-15-2009 11:51 PM
To remove the lines in my file gsiva Shell Programming and Scripting 5 03-05-2009 05:13 AM
remove lines from file bluemoon1 Shell Programming and Scripting 9 11-09-2007 12:40 AM



All times are GMT -4. The time now is 06:16 AM.