Using ex
/vi
editor and globstar option (syntax similar to awk
and sed
):
ex +"/string1/,/string3/p" -R -scq! file.txt
where aaa
is your starting point, and bbb
is your ending text.
To search recursively, try:
ex +"/aaa/,/bbb/p" -scq! **/*.py
Note: To enable **
syntax, run shopt -s globstar
(Bash 4 or zsh).