May 2013
Beginner to intermediate
384 pages
7h 40m
English
We may require to print a certain section of text lines, based on conditions such as a range of line numbers, and a range matched by a start and end pattern. Let's see how to do it.
We can use utilities such as awk, grep, and sed to perform the printing of a section based on conditions. Still, I found awk to be the simplest one to understand. Let's do it using awk.
M to N, use the following syntax:
$ awk 'NR==M, NR==N' filename
Or, it can take the stdin input as follows:
$ cat filename | awk 'NR==M, NR==N'
M and N with numbers as follows:$ seq 100 | awk 'NR==4,NR==6' 4 5 6
Read now
Unlock full access