0

I have a file "testfile" with 10 lines. I want to print lines 3 (lower) to 6(upper) out of these lines. So I use cat testfile | sed -n 3,6p to print the lines. Now if I calculate the upper limit to be displayed based on some calculation and the result is saved in a variable say "y". Assume y=6, how can I use the same sed command now??

sed -n 3,$yp doesn't work as yp is considered like a variable here. How do I distinguish between $y and p here.

codecrazy46
  • 275
  • 1
  • 5
  • 14

1 Answers1

-1

With curly braces:

sed -n 3,${y}p FILE

and the useless use of cat can be avoided, too. :)

user unknown
  • 35,537
  • 11
  • 75
  • 121