Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-07-2005, 07:38 PM   #1
Registered: Dec 2003
Distribution: Debian, FreeBSD
Posts: 310

Rep: Reputation: 35
Bash, using variable in sed

This is the command I'm trying to use..

sed -n '1p' filename

What I am trying to do is have "1" be a variable that will have a counter on it that gets incremented in a while loop.. The part I'm trying to figure out is how to use a variable inside of sed.

I tried this, and a few variations, but its not working..


sed -n '/$VARIABLE/p' filename

Old 11-07-2005, 08:44 PM   #2
LQ Guru
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,670

Rep: Reputation: 229Reputation: 229Reputation: 229
my guess


sed -n "${VARIABLE}p" filename

Steve Stites
Old 11-07-2005, 08:52 PM   #3
Registered: Dec 2003
Distribution: Debian, FreeBSD
Posts: 310

Original Poster
Rep: Reputation: 35
That was easy enough

Old 11-12-2005, 08:41 AM   #4
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Invest some time learning the difference between single and double quotes in shells. It'll repay you in spades. For starters:
VAR="aa            bb                  cc"
echo $VAR
echo "$VAR"
echo '$VAR'


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
sed doesn't accept $variable in bash script chii-chan Programming 6 05-28-2005 08:07 AM
insert output of sed into a variable hwouters Linux - General 3 11-06-2004 08:54 PM
sed not working if value is passed thru a variable containg value suchi_s Programming 7 10-29-2004 08:41 AM
sed and variable chirophil91 Programming 2 10-19-2004 04:23 AM
Expanding shell variable in sed goofyheadedpunk Programming 4 09-11-2004 06:17 PM

All times are GMT -5. The time now is 06:44 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration