Sample Header Ad - 728x90

Perl or sed script to remove a specific content of a file from another bigger file

-4 votes
5 answers
105 views
I have a file **(FILE1)** with some repeated sections as below (example): LINE 1 ABCD LINE 2 EFGA LINE 3 HCJK REMOVE LINE11 REMOVE LINE12 REMOVE LINE13 LINE 4 ABCDH LINE 5 EFGAG LINE 6 HCJKD REMOVE LINE11 REMOVE LINE12 REMOVE LINE13 LINE 7 ABCDH LINE 8 EFGAG LINE 9 HCJKD I have several such files. In a pattern file (**PATTERN**) I have these removable lines stored. REMOVE LINE11 REMOVE LINE12 REMOVE LINE13 I want to write a sed, awk (bash code) or a Perl code to remove all the sections of of **FILE** that match the content of the file **PATTERN**. Another requirement is to remove all but leave the first occurrence only.
Asked by Pratap (45 rep)
Aug 6, 2025, 06:03 AM
Last activity: Aug 7, 2025, 03:11 AM