LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 12-01-2008, 01:11 PM   #1
gerben12
LQ Newbie
 
Registered: Oct 2007
Distribution: SuSE, Redhat, Debian
Posts: 25

Rep: Reputation: 15
How do I actually delete a line using bash?


Hello,

I was wondering: how can I actually delete a line from a list with just one command?

Say I have this list:

ITEM1
ITEM2
ITEM3

Now I want to remove say ITEM2.
How can I do this in one command?
Yes, I can copy it then use "grep -v" or "sed 2d" and copy it back.
But is there one command that does this in one time?
It saves me a lot of copy and pasting

Thanks in advance.
 
Old 12-01-2008, 01:14 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Code:
sed -i '2d' file
 
Old 12-03-2008, 02:54 AM   #3
gerben12
LQ Newbie
 
Registered: Oct 2007
Distribution: SuSE, Redhat, Debian
Posts: 25

Original Poster
Rep: Reputation: 15
Yep thank you, that works.
 
  


Reply

Tags
bash, sed, shell


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash shell script read file line by line. Darren[UoW] Programming 51 07-04-2013 09:16 PM
BASH: read every line in the files and use the line as parameters as another program tam3c36 Programming 10 12-07-2010 02:42 PM
sed to delete a line for a word and line above cmontr Programming 11 07-03-2008 09:33 AM
SED - Delete line above or below as well as matching line... OldGaf Programming 7 06-27-2008 12:51 AM
delete a line containing a pattern and the next line of a text file powah Programming 3 01-31-2007 06:34 PM


All times are GMT -5. The time now is 01:45 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration