So I have a file like this:
echo 'this line is added for demo purpose'
echo 'do not extract this line and the line above'
#!/usr/bin/env bash
# header: add, replace, and delete header lines.
# 
# Example usage:
# $ seq 10 | header -a 'values'
# $ seq 10 | header -a 'VALUES' | header -e 'tr "[:upper:]" "[:lower:]"'
# $ seq 10 | header -a 'values' | header -d
# $ seq 10 | header -a 'multi\nline' | header -n 2 -e "paste -sd_"
#
# See also: body
#
# Author: http://jeroenjanssens.com
usage () {
cat << EOF
header: add, replace, and delete header lines.
usage: header OPTIONS
OPTIONS:
...
}
# i don't want
# these comments
# even if 
# these lines match
And I want to extract all the lines matching regex ^(#.*)|(\s*)$,
from the first line in the file that matches, consecutively to the last line that matches.
The desired result of extraction should be
#!/usr/bin/env bash
# header: add, replace, and delete header lines.
# 
# Example usage:
# $ seq 10 | header -a 'values'
# $ seq 10 | header -a 'VALUES' | header -e 'tr "[:upper:]" "[:lower:]"'
# $ seq 10 | header -a 'values' | header -d
# $ seq 10 | header -a 'multi\nline' | header -n 2 -e "paste -sd_"
#
# see also: body
#
# Author: http://jeroenjanssens.com
How do I do this?
I think I can extract all consecutively matching lines with regex in multiline mode, but I only want the first part of the match.
Update:
I want regex ^(#.*)|(\s*)$ to match
- comments with a #at the beginning of the lines
- empty lines (like the one after # Author)
- lines only contain empty spaces



# Author...line? and also rest of the line# See also: body...., and howSeechanged toseethere?# Authorto be matched by regex^(#.*)|(\s*)$and be extracted. The see also part was an editing mistake and it's now fixed. :)^(#.*)|(\s*)$.