Dear Experts,
Here is my input files which has various sections of data.
SURVEY RESULT
NUMADDR NUB NUBA
4-9XXXXXXXXXXX 1244359 1099510
4-9YYYYYYYYYYY 692 586
4-2XXXXXXXXXXX 223 147
4-8YYYYYYYYYYY 1 1
SUMADDR NUB NUBA
4-9XXXXXXXXXXX 1244359 1099510
4-9YYYYYYYYYYY 692 586
4-2XXXXXXXXXXX 223 147
4-8YYYYYYYYYYY 1 1
TOTNSUB NUB NUBA
4-9XXXXXXXXXXX 128888 1099510
4-9YYYYYYYYYYY 692 586
4-2XXXXXXXXXXX 223 147
4-8YYYYYYYYYYY 1 1
TOTNSUBA NUB NUBA
4-9XXXXXXXXXXX 129999 1099510
4-9YYYYYYYYYYY 692 586
4-2XXXXXXXXXXX 223 147
4-8YYYYYYYYYYY 1 1
The below awk command to get data matching first column NUMADDR till number of lines specified in command.
I need only change here is instead of mentioning static number of lines for (y=0;y>4;y++) need all lines till next blank line.
awk '{a[++i]=$0;}END{for (j=1;j<NR;j++) {if (a[j]~"NUMADDR") {for (y=0;y>5;y++) print a[j+y]}}}' file
Output should be as below
NUMADDR NUB NUBA
4-9XXXXXXXXXXX 1244359 1099510
4-9YYYYYYYYYYY 692 586
4-2XXXXXXXXXXX 223 147
4-8YYYYYYYYYYY 1 1