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.
  • 33,075
  • 16
  • 78
  • 86
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
  • 72,551
  • 14
  • 101
  • 128