0

In bash, I defined a variable n, from which value of line number to the last line is what I am going to delete.

I tried

sed -i '${n},$d' file

but the error msg is:

sed: -e expression #1, char 5: extra characters after command

Any thoughts about how to correct the use of sed? I suspect it is because of two $ in the sed, one is for variable, the other is for the last line number.

Benjamin W.
  • 38,596
  • 16
  • 96
  • 104
Lei Zhang
  • 103
  • 1
  • 2
  • 7

1 Answers1

1

For portability, clarity, and safety, the following would be reasonable:

sed -i.bak -e "${n},\$d" file
peak
  • 88,177
  • 15
  • 123
  • 150