LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 08-31-2012, 11:55 AM   #1
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Rep: Reputation: Disabled
i want to pass a line number variable in sed


num=10
sed -n '$num p' test.txt


sed -n '10 p' test.txt works

however i am putting the sed command in a loop and the line number is not static
Can someone please help me how to achive this.
 
Old 08-31-2012, 12:47 PM   #2
byannoni
Member
 
Registered: Aug 2012
Location: /home/byannoni
Distribution: Arch
Posts: 128

Rep: Reputation: 36
Use double quotes:
Code:
sed -n "$num p" test.txt
 
1 members found this post helpful.
Old 08-31-2012, 12:56 PM   #3
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by byannoni View Post
Use double quotes:
Code:
sed -n "$num p" test.txt
thnks a lot byannoni
 
Old 08-31-2012, 06:19 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
It looks like it's time for you to learn the difference between double and single quotes. Start here:

http://mywiki.wooledge.org/Quotes
http://wiki.bash-hackers.org/syntax/quoting
 
  


Reply

Tags
sed



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
[SOLVED] Insert line using sed or awk at line using line number as variable sunilsagar Programming 11 02-03-2012 10:48 AM
[SOLVED] How to pass sed address by shell variable? kaz2100 Programming 3 08-02-2011 08:21 PM
[SOLVED] Sed - print line number along with the line ? ntpntp Linux - Newbie 6 01-30-2011 05:58 AM
Sed search for variable and delete entire line, but variable contains forward /'s Passions Programming 2 11-10-2008 03:44 PM
Pass a variable as a line number in sed dx0r515t Programming 7 03-30-2007 04:55 PM

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

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