> For the complete documentation index, see [llms.txt](https://til.yulrizka.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.yulrizka.com/unix/get-all-line-except-n-last-one.md).

# get all line except n last one

with `head -n <negative number>` we can get the output except n lines

example

```
cat a.txt | head -n -1
```

will gives as the content of a.txt except the last one

Let say we have file 1 2 3 4 5, and with grep we want to only get 1 2 3.

we can achive this with ls and grep

```
$ ls | grep 4 -B 100000000 | head -n -1
```

the -B show 100000000 lines before matched line, and the head -n -1 removes the matched
