Answer the question
In order to leave comments, you need to log in
How to search and replace multiple lines of text in Linux?
There is a task to cut out the google tag manager code from a huge number of pages. Pages are just php on the server, I wanted to find a quick solution, but so far it has not been possible.
The code itself looks something like this
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-000000"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-000000');</script>
<!-- End Google Tag Manager -->
<!-- Google Tag(.|\n|\t|\r)* End Google Tag Manager -->
I find it in any editor. find . -type f -iname "*.php" | xargs perl -i.bak -pe "s/<(.*) Google Tag (.|\n|\r)* End Google Tag Manager -->$//g"
find . -type f -iname "*.php" -exec sed -i "s/<(.*) Google Tag (.|\n|\r)* End Google Tag Manager -->$//g" {} \;
find ~~m~test -type f -iname "*.php" -exec sed -i '/<!-- Google Tag Manager -->/,/<!-- End Google Tag Manager -->/d' {} \;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question