LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-16-2007, 02:01 PM   #1
hraposo
Member
 
Registered: Aug 2004
Posts: 370

Rep: Reputation: 30
Delete a line in a file by script


If I in one script to place the line:

echo “deb ftp://ftp.videolan.org/pub/videolan/ubuntu to dapper universe” >> /etc/apt/sources.list

this adds a repository sources.list.

It has some form to erase a line of a file or commenting, by one script?
 
Old 08-16-2007, 02:20 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Do you mean that you want a command that will delete or modify a line based on content?

SED is the tool I know the best. Suppose you want to delete all lines beginning with "dog":

sed -i '/^dog/ d' filename

Or, add the comment character to all lines containing "dog":

sed -i '/dog/ s/^/#/' filename

Best SED tutorial I have seen (plus other good stuff): http://www.grymoire.com/Unix/
 
Old 08-16-2007, 02:23 PM   #3
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Code:
sed -i~ '/address/d'
or
Code:
sed -i~ '/address/s/^/#/'
would be a couple of ways, if I understand your question. If you use this and you're not using gnu sed, you'll need to do the redirect/rename dance.

-- Pixellany beat me to it - fancy formatting slows ya down.

Last edited by slakmagik; 08-16-2007 at 02:24 PM. Reason: redundancy mea culpa
 
  


Reply

Tags
sed



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script to Delete line if pattern exists topcat Programming 22 08-23-2011 04:58 AM
unix shell script:How to delete the first line in a file?? rche3252 Programming 6 03-03-2010 07:32 AM
delete a line containing a pattern and the next line of a text file powah Programming 3 01-31-2007 05:34 PM
delete line specified by variable wihin shel script with sed lnchatterbox Linux - Newbie 2 02-23-2004 01:24 PM
How to delete a line from a text file with shell script programming Bassam General 1 01-28-2004 08:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:00 PM.

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
Open Source Consulting | Domain Registration