Question: There are unknown number of lines in a file. How to delete nth line (when counted from the bottom) with one-liner command (you may use more than one if it is necessary) on Unix platform.

Answer: 
To remove for example the 4th line from the bottom using `sed`:

```
tac input | sed '4d' | tac

```

To overwrite the input file:

```
tmpfile=$(mktemp)
tac input | sed '4d' | tac > "$tmpfile" && mv "$tmpfile" input

```
Neither standard `sed` nor `awk` support editing in place.

For that, you better use `ed(1)` or `ex(1)`:

```
printf '$-%dd\nw\n' 1 | ed -s your_file

```

Or with here-doc

```
ed -s <<'EOT' your_file
$-1d
w
EOT

```

With advanced shells like `bash`, `zsh` or`ksh93` you can use the `$'...'` syntax and here-strings:

```
ed -s <<<$'$-1d\nw' your_file 

```

Notice that the `$` address means the last line from the file; so the index 1 there is **0-based**; for the 1st line from the end replace the 1 with 0 (`$-0`), for the 3nd with 2 (`$-2`), etc.

Putting it in a function:

```
del_nth_line_from_end(){ printf '$-%dd\nw\n' "$(($2-1))" | ed -s "$1"; }

```

Instead of `ed -s` you can use `ex -s` or `vim -es` everywhere.