LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 11-07-2005, 07:38 PM   #1
fur
Member
 
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..


VARIABLE="1"

sed -n '/$VARIABLE/p' filename


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

Rep: Reputation: 188Reputation: 188
my guess

VARIABLE=1

sed -n "${VARIABLE}p" filename

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

Original Poster
Rep: Reputation: 35
That was easy enough

Thanks
 
Old 11-12-2005, 08:41 AM   #4
eddiebaby1023
Member
 
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:
Code:
VAR="aa            bb                  cc"
echo $VAR
echo "$VAR"
echo '$VAR'
 
  


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
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 11:17 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration