Hi would like extract N number of lines after matching the first incidence of a string printing the N lines following using awk. The string is repeated a number of times in the file I am processing . I have tried using this command:
'c&&c--;/XCHT/{c=10}'
This prints all incidences of the match + 10 lines. I have seen various versions of this command after extensive searches but all versions produce largely the same result as below. I have looked around to find . I would like some tips on how to modify this command to achieve the result
The result of the match I would like to achieve is as follows
| XCHT | |
|-----------------|----|
| 柴胡chaihu | 24 |
| 黄芩huangqin | 9 |
| 法半夏banxia | 12 |
| 生姜shengjiang | 9 |
| 刺五加ciwujia | 9 |
| 大枣dazao | 6 |
| 炙甘草zhigancao | 9 |
| | |
| | |
A section of the file looks like this:
## XCHT
| XCHT | |
|-----------------|----|
| 柴胡chaihu | 24 |
| 黄芩huangqin | 9 |
| 法半夏banxia | 12 |
| 生姜shengjiang | 9 |
| 刺五加ciwujia | 9 |
| 大枣dazao | 6 |
| 炙甘草zhigancao | 9 |
| | |
| | |
## XCHT+CM
| | |
|-----------------|----|
| 柴胡chaihu | 24 |
| 黄芩huangqin | 9 |
| 法半夏banxia | 12 |
| 干姜ganjiang | 9 |
| 五味子wuweizi | 9 |
| 炙甘草zhigancao | 9 |
| | |
| | |
## XCHT+TM
| XCHT+TM | |
|----------------- |----|
| 柴胡chaihu | 24 |
| 黄芩huangqin | 9 |
| 法天花粉tianhuafen | 12 |
| 生姜shengjiang | 9 |
| 刺五加ciwujia | 12 |
| 大枣dazao | 6 |
| 炙甘草zhigancao | 9 |
| | |
| | |
| XCHT-HQin+FL | |
|-----------------|----|
| 柴胡chaihu | 24 |
| 黄茯苓fuling | 12 |
| 法半夏banxia | 12 |
| 生姜shengjiang | 9 |
| 刺五加ciwujia | 9 |
| 大枣dazao | 6 |
| 炙甘草zhigancao | 9 |
| | |
| | |
## XCHT-DZ+ML
| XCHT-DZ+ML | |
|-----------------|-----|
| 柴胡chaihu | 12 |
| 黄芩huangqin | 4.5 |
| 法半夏banxia | 6 |
| 生姜shengjiang | 4.5 |
| 刺五加ciwujia | 4.5 |
| 牡蛎 muli | 6 |
| 炙甘草zhigancao | 4.5 |
| | |
| | |
The result of the command 'c&&c--;/XCHT/{c=10}' on the file
| XCHT | |
|-----------------|----|
| 柴胡chaihu | 24 |
| 黄芩huangqin | 9 |
| 法半夏banxia | 12 |
| 生姜shengjiang | 9 |
| 刺五加ciwujia | 9 |
| 大枣dazao | 6 |
| 炙甘草zhigancao | 9 |
| | |
| | |
| XCHT | |
|-----------------|----|
| 柴胡chaihu | 24 |
| 黄芩huangqin | 9 |
| 法半夏banxia | 12 |
| 干姜ganjiang | 9 |
| 五味子wuweizi | 9 |
| 炙甘草zhigancao | 9 |
| | |
| | |
| XCHT+TM | |
|----------------- |----|
| 柴胡chaihu | 24 |
| 黄芩huangqin | 9 |
| 法天花粉tianhuafen | 12 |
| 生姜shengjiang | 9 |
| 刺五加ciwujia | 12 |
| 大枣dazao | 6 |
| 炙甘草zhigancao | 9 |
| | |
| | |
| XCHT-DZ+ML | |
|-----------------|-----|
| 柴胡chaihu | 12 |
| 黄芩huangqin | 4.5 |
| 法半夏banxia | 6 |
| 生姜shengjiang | 4.5 |
| 刺五加ciwujia | 4.5 |
| 牡蛎 muli | 6 |
| 炙甘草zhigancao | 4.5 |
| | |
| | |
| Xiao Chaihi Tang -HQ+BS | |
|-------------------------|----|
| 柴胡chaihu | 24 |
| 白芍baishao | 9 |
| 法半夏banxia | 12 |
| 生姜shengjiang | 9 |
| 刺五加ciwujia | 9 |
| 大枣dazao | 6 |
| 炙甘草zhigancao | 9
The tables are a bit wonky as a result of copying them to the webpage. Any help of advice will be much appreciated .
|part of the file or did you add them here only?awk? If you have GNUgrepyou could just dogrep -m1 -A10 XCHT.|are part of the file used as table separators##really present above some blocks in your input, sometimes with a blank line after them, other times not?