We may need to print a selected portion of a file, either a range of line numbers or a range matched by a start and end pattern.
Printing text between line numbers or patterns
Getting ready
Awk, grep, or sed will select lines to print, based on condition. It's simplest to use grep to print lines that include a pattern. Awk is the most versatile tool.
How to do it...
To print the text between line numbers or patterns, follow these steps:
- Print the lines of a text in a range of line numbers, M to N:
$ awk 'NR==M, NR==N' filename
Awk can read from stdin:
$ cat filename | awk &apos...