> For the complete documentation index, see [llms.txt](https://cajac.gitbook.io/ctf-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cajac.gitbook.io/ctf-notes/misc/text-processing/print-lines-in-files.md).

# Print Lines in Files

## Print lines with Awk

To print one specific line with `awk`

```bash
awk 'NR == 11 {print $0}' test.txt
```

To print lines up till, but not including, line 5 with `awk`

```bash
awk 'NR < 5 {print $0}' test.txt
```

To print lines from, and including, line 5 with `awk`

```bash
awk 'NR >= 5 {print $0}' test.txt
```

To print lines between, and including, lines 5-10 with `awk`

```bash
awk 'NR >= 5 && NR <= 10 {print $0}' test.txt
```

## Print lines with Sed

To print one specific line with `sed`

```bash
sed -n '11p' test.txt
```

To print lines up till, and including, line 5 with `sed`&#x20;

```bash
sed -n '1,5p' test.txt
```

To print line lines from, and including, line 5 with `sed`&#x20;

```bash
sed -n '5,$p' test.txt
```

To print lines between, and including, lines 5-10 with `sed`

```bash
sed -n '5,10p' test.txt
```

## Resources

**awk** - Linux manual page: <https://man7.org/linux/man-pages/man1/awk.1p.html>

**sed** - Linux manual page: <https://man7.org/linux/man-pages/man1/sed.1.html>
