Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

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?
0
virmaior
Asked:
virmaior
  • 2
  • 2
2 Solutions
 
ahoffmannCommented:
assuming you have a perl script which makes your changes for one file:

find /path/to/dir/where/to/start/ -type f -name \*.php -exec your-script.pl -pi {} \;

# to be improved in many ways ...
0
 
virmaiorAuthor Commented:
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.
0
 
ahoffmannCommented:
for multi-line regex see m operator
  man perlre
0
 
virmaiorAuthor Commented:
thanks!

I think these are the pieces i need.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now