Delete text between 2 patterns using sed

By xngo on February 21, 2019

# Delete text between patterns, excluding the lines containing these 2 patterns:
sed '/PATTERN-1/,/PATTERN-2/{//!d}' input.txt
 
 
# Delete text between patterns, including the lines containing these 2 patterns:
sed '/PATTERN-1/,/PATTERN-2/d' input.txt
 
# To delete all the lines after PATTERN, use this
sed '/PATTERN/,$d' input.txt

Reference

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.