LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   i want to pass a line number variable in sed (http://www.linuxquestions.org/questions/linux-newbie-8/i-want-to-pass-a-line-number-variable-in-sed-4175425001/)

figure20012 08-31-2012 11:55 AM

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.

byannoni 08-31-2012 12:47 PM

Use double quotes:
Code:

sed -n "$num p" test.txt

figure20012 08-31-2012 12:56 PM

Quote:

Originally Posted by byannoni (Post 4769368)
Use double quotes:
Code:

sed -n "$num p" test.txt

thnks a lot byannoni

David the H. 08-31-2012 06:19 PM

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


All times are GMT -5. The time now is 12:51 AM.