sed '/start_pattern_here/,/end_pattern_here/!d' inputfile awk '$0=="pattern1" {p=1}; p; $0=="pattern2" {p=0}' file