Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-23-2004, 12:18 PM   #1
LQ Newbie
Registered: Feb 2004
Posts: 2

Rep: Reputation: 0
delete line specified by variable wihin shel script with sed


I am trying to delete a line from a file using sed.

This works:
sed '4d' inputfile
#deletes 4th line from inputfile

BUT: I have the line stored in a shell variable $line

This doesn't work:
sed '$(line)d' inputfile

Any ideas? I've already tried most combinations of brackets and ",' etc.
Thanx in advance!
Old 02-23-2004, 01:00 PM   #2
Senior Member
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
This seems to work ok.....
The variable is in double quotes "$line" and the command is in single quotes 'd'



cat file1.txt | sed -e "$line"'d' > file2.txt
Old 02-23-2004, 02:24 PM   #3
LQ Newbie
Registered: Feb 2004
Posts: 2

Original Poster
Rep: Reputation: 0
Thanx alot! It works now!

Last edited by lnchatterbox; 02-23-2004 at 02:47 PM.


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
Shell Script to Delete line if pattern exists topcat Programming 22 08-23-2011 05:58 AM
unix shell script:How to delete the first line in a file?? rche3252 Programming 6 03-03-2010 08:32 AM
[SOLVED] delete the end of each line in a file with sed angel115 Linux - Newbie 3 11-16-2005 05:41 PM
sed doesn't accept $variable in bash script chii-chan Programming 6 05-28-2005 08:07 AM
trying to delete a line with sed deoren Linux - General 2 01-03-2005 10:26 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:24 PM.

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