regex - Delete multi-line pattern starting on first line of file only -


from bash script, i'm trying delete pattern file following:

<% delete tag %><? keep tag ?> <% keep tag %> 

but if tag @ beginning of file, following untouched:

text keep <% don't delete me %> 

i've tried piece answers on other questions, haven't been able come command work this.

is possible sed? there different tool work better?

if want give perl chance should work:

perl -0777 -pe 's/^\s*<%.*?%>//s' file  <? keep tag ?> <% keep tag %> 

breakup:

  • -0777 : slurp mode match file text including newlines
  • ^\s*: match start followed 0 or more white-spaces
  • <%.*?%>: match tag (lazy)

to save changes file:

perl -i -0777 -pe 's/^\s*<%.*?%>//s' file 

Comments

Popular posts from this blog

html - How to custom Bootstrap grid height? -

javascript - pass values from mssql to views in node -

image - python get coordinates (pixels) of corresponding points from clicks -