I'm trying to create a shell script that would read through code and pull out sections.
An example of the code would be:
method_name1()
[Marker] CODE-1234
# Comment 1
# Comment 2
code...
method_name2()
code...
method_name3()
[Marker] CODE-456 possible other text
# Comment 1
code...
method_name4()
[Marker] CODE-ABC
code...
So what I'm trying to do is grep through all the source code looking for [Marker] CODE-
and then also collect all of the following lines that start with some whitespace followed by a pound comment.
Not all methods would have a marker, not all markers have comments, and there can be one or more lines that make up the comment.
There is the grep parameter -A which gets lines after a match, but it is always for a specific number of lines, whereas this code could have zero to a hundred lines of comments after.
I've thought about trying -B 1 to get the method name and -A 5 to just always get 5 lines and then separately parse them for the #
symbol, but I just think there should be another/cleaner way.
The end result would be a simple to read table such as:
| method | marker | comments |
|--------------|-----------|------------------------------------|
| method_name1 | CODE-1234 | Comment 1. Comment 2. |
| method_name3 | CODE-456 | (possible other text) Comment 1. |
| method_name4 | CODE-ABC | -- |
So it is possible to "double grep"?