Command to delete specific lines after searching for a phrase from a file
Am looking for a help in Linux command that performs/does the following:
Searches for a particular word/phrase case-insensitively in a given file, and then remove/delete the immediate next 'n' lines including the line where the word/phrase was matched in the given file.
EXAMPLE: If I try to search for the phrase "CREATE FUNCTION plpgsql_call_handler" case-insensitively and if it matches at line no.102644, then I expect to delete the line no.102644 and the immediate next 2 lines from the given file. In this case, I expect to delete line nos. 102644,102645,102646.
Solution 1:
sed -i '/CREATE FUNCTION plpgsql_call_handler/I ,+2d' <filename>
Believe this'll work. Back the file up first before trying it in anger.