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.
  • 46,058
  • 19
  • 106
  • 116
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
  • 105,803
  • 17
  • 152
  • 177