LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 02-23-2004, 11:18 AM   #1
lnchatterbox
LQ Newbie
 
Registered: Feb 2004
Posts: 2

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


Hi!

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, 12:00 PM   #2
homey
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'

Code:
#!/bin/bash

line="1,4"

cat file1.txt | sed -e "$line"'d' > file2.txt
 
Old 02-23-2004, 01:24 PM   #3
lnchatterbox
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 01:47 PM.
 
  


Reply


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:38 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
Open Source Consulting | Domain Registration