Interview Prep/Shell Scripting/Text processing: grep, sed, awk, cut, sort, uniq

How do you print lines between two patterns with `sed` and `awk`?

IntermediateConceptText processing: grep, sed, awk, cut, sort, uniq
Answer
sed -n '/^\[mysqld\]/,/^\[/p' my.cnf                 # inclusive range
awk '/BEGIN CERT/,/END CERT/' bundle.pem
awk '/^\[mysqld\]/{f=1; next} /^\[/{f=0} f' my.cnf    # contents only, without markers

Range patterns turn on at the first pattern and off after the second. If the end pattern never appears, they print to the end of the file.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Text processing: grep, sed, awk, cut, sort, uniq