Delete Between Two Matching Lines
This page answers questions like these:
- How to delete the lines between two matching lines?
- How to remove the lines between two matching patterns?
- How to delete the lines between two matching strings?
- How to erase the lines between two matching patterns?
Related Links:
Output the Lines Between Two Matching Lines
Output Lines of a File in Reverse Order
Join Lines of Text File Together
Count Occurrences of a Hexadecimal Sequence in a File
Count Occurrences of a String in a File
Find Positions of a Hexadecimal Sequence in a File
Delete the Lines Between Two Matching Lines (Inclusive)
sed '/PATTERN1/,/PATTERN2/d' FILE ...
- For each file in FILE ... start at the first line of the file and do the following:
- If the line doesn’t match PATTERN1, output the line, then go to step 1.
- Ignore the line matching PATTERN1, and move to the next line.
- If the line doesn’t match PATTERN2, ignore the line, then go to step 3.
- Ignore the line matching PATTERN2, and move to the next line.
- Go back to step 1.
- Pros: Handles multiple files.
- Cons: Assumes matching pairs: If a file ever has a line matching PATTERN1 with no subsequent line matching PATTERN2, all lines after and including the one matching PATTERN1 are removed. Assumes no nesting of pairs.
Related Links:
Output the Lines Between Two Matching Lines
Output Lines of a File in Reverse Order
Join Lines of Text File Together
Count Occurrences of a Hexadecimal Sequence in a File
Count Occurrences of a String in a File
Find Positions of a Hexadecimal Sequence in a File
Home > Linux / Unix > Delete Between Two Matching Lines
Tags: delete lines between two matching patterns, remove lines between two matching patterns, linux, unix, solaris, bsd, aix
Copyright © HelpDoco.com
file-delete-lines-between-two-matching-lines.txt
Linux-Unix/delete-lines-between-two-matching-lines.htm
1