May 2017
Beginner
552 pages
28h 47m
English
To print the text between line numbers or patterns, follow these steps:
$ awk 'NR==M, NR==N' filename
Awk can read from stdin:
$ cat filename | awk 'NR==M, NR==N'
$ seq 100 | awk 'NR==4,NR==6'
4
5
6
$ awk '/start_pattern/, /end _pattern/' filename
Consider this example:
$ cat section.txt
line with pattern1
line with pattern2
line with pattern3
line end with pattern4
line with pattern5
$ awk '/pa.*3/, /end/' section.txt
line with pattern3
line end with pattern4
The patterns used in awk are regular expressions.