Saturday, January 27, 2024

[SOLVED] Delete text between 2 patterns using sed

Issue

I'm trying to remove some JavaScript between two patterns. The patterns are:

/* React App Start */

And

/* React App End */

I can successfully remove the JavaScript with the following:

sed -i -e '/\/\* React App Start \*\//,/\/\* React App End \*\//d' views/layouts/index.html

However, this also removes the patterns which I do not want. Therefore, I tried the following, but it only removes some of the JavaScript:

sed -i -e '/\/\* React App Start \*\//,/\/\* React App End \*\//{//!d;}' views/layouts/index.hml

Can anyone help please? I'm on a Mac.


Solution

To get this to work, I had to enter a new line before the last pattern.



Answered By - Rob H
Answer Checked By - Senaida (WPSolving Volunteer)