LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 06: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, 07:44 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,340

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
my guess

VARIABLE=1

sed -n "${VARIABLE}p" filename

-------------------
Steve Stites
 
Old 11-07-2005, 07: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, 07: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



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 07:07 AM
insert output of sed into a variable hwouters Linux - General 3 11-06-2004 07:54 PM
sed not working if value is passed thru a variable containg value suchi_s Programming 7 10-29-2004 07:41 AM
sed and variable chirophil91 Programming 2 10-19-2004 03:23 AM
Expanding shell variable in sed goofyheadedpunk Programming 4 09-11-2004 05:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:09 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