Link to home
Start Free TrialLog in
Avatar of virmaior
virmaiorFlag for United States of America

asked on

How do I perform a multi-file, multi-line, multi-directory find/replace in linux?

While I've looked at:

http://rushi.wordpress.com/2008/08/05/find-replace-across-multiple-files-in-linux/

and

http://www.liamdelahunty.com/tips/linux_search_and_replace_multiple_files.php

when I try to use them, neither accomplishes what I am looking for.  basically I want to do site-wide replace of a multiple line javascript by using a command line find/replace in linux.


in terms of modifying perl -pi -w -e 's/\.\.\/includes\/style\.css/admin\.css/g;' *.php

I am not sure how to change it to handle (a) multiple lines and (b) multiple directories.

here's what I want to find:

<!-- Start Quantcast tag -->
<script type="text/javascript">
if(window.location.protocol != 'https:') {
    document.write('<script src="http://edge.quantserve.com/quant.js" type="text/javascript"><\/script>');
    document.write('<script type="text/javascript">_qacct="p-XXXXXXXXXXXXXXXX-";quantserve();<\/script>');
}
</script>
<!-- End Quantcast tag -->

and replace it with:

<script type="text/javascript">
_qoptions={
qacct:"p-XXXXXXXXXX-"
};
</script>
<script type="text/javascript" src="//secure.quantserve.com/quant.js"></script>
<noscript>
<img src="//secure.quantserve.com/pixel/p-XXXXXXXXXXX-.gif" style="display: none;" border="0" height="1" width="1" alt="Quantcast"/>
</noscript>

any suggestions?
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of virmaior

ASKER

definitely a step in the right direction...

I don't have the multi-line regex as of yet, so i'm going to leave it open for a day or two to see if anyone appears with one.

if not, i'll give you the points and ask that in the perl area.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks!

I think these are the pieces i need.