Unix/Linux Go Back    


UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

vi to remove lines in file

UNIX for Dummies Questions & Answers


Tags
vim

 
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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:


Code:
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

Last edited by Don Cragun; 09-07-2015 at 03:50 AM.. Reason: Add CODE and ICODE tags.
Sponsored Links
    #2  
Old Unix and Linux 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:


Code:
:g/outdated/d

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


Code:
: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.

Last edited by Don Cragun; 09-07-2015 at 03:51 AM.. Reason: Add CODE tags.
Sponsored Links
    #3  
Old Unix and Linux 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
Code:
:g/outdated/d

this wil delete all lines with the worh outdated.

You can also use
Code:
:1,10/outdated/d

to delete lines from 1 to 10 with the word outdated.

Last edited by Don Cragun; 09-07-2015 at 03:53 AM.. Reason: Remove confusing single quotes and add CODE tags to remove confusion.
Sponsored Links
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 06:45 PM
remove : lines from file aronmelon Shell Programming and Scripting 5 06-10-2009 12:46 PM
remove lines from file lweegp Shell Programming and Scripting 10 03-16-2009 12:51 AM
To remove the lines in my file gsiva Shell Programming and Scripting 5 03-05-2009 06:13 AM
remove lines from file bluemoon1 Shell Programming and Scripting 9 11-09-2007 01:40 AM



All times are GMT -4. The time now is 07:52 AM.