Problem with sed

Hi all,

I want to use sed command to search lines by line number. I give the command:

#sed -n '3p;3q'

Now, I don't want to use the exact value. Instead, I want to use the values of line numbers by variables. I tried using above command but that's not working. What I exactly want:

#sed -n '$var p; $var q'

How will I able to use variables with above command?

Thanks in advance
Deepak Tiwari

$ var=2 ; echo "one\ntwo\nthree" |nl |sed -n "${var}p"
     2  two

Use double quotes, single quotes prevent the expansion of the variables by your shell.

sed -n "$var p; $var q"

Regards

Thanks to you both!!

Both worked.