
Cyré
New User
May 2, 2008, 3:14 PM
Post #5 of 5
(4914 views)
|
Re: [Caunter] recursive replace string in all files with specific name
[In reply to]
|
Can't Post
|
|
$ find . -name *.props -exec perl -p -i -e 's/string_to_replace/new_string/' {} \; So, let's say I want all *.php, *.htm*, *.xml, *.css, *.js files to be stripped of preceding spaces (indent code) and double newlines/linebreaks, for example, this:
<?php // --------------------------------------------------------------------------- // // LICENSE: // // This file is part of . and all its parts are licensed under // the GPL version 2. see: http://www..net/help/help_about_gpl.php // for more information. // // --------------------------------------------------------------------------- // First line defense. if (file_exists(dirname(__FILE__)."/first_defense.php")) { include_once(dirname(__FILE__)."/first_defense.php"); block_refererspam(); } define('__SILENT__', TRUE); // apparently also defined in pv_core // $marco (who hates php notices) // define('IN', TRUE); define('LIVEPAGE', TRUE); include_once("v_core.php"); should become:
<?php if (file_exists(dirname(__FILE__)."/first_defense.php")) { include_once(dirname(__FILE__)."/first_defense.php"); block_refererspam(); } define('__SILENT__', TRUE); define('LIVEPAGE', TRUE); include_once("v_core.php"); Does anyone have that laying around? ;-) Stripping tabs, spaces, empty lines and comments from an entire webserver doc root (plus subdirs), without leaving a backup (assume a full backup exists). Also, in HTML of course double spaces are only important if they are enclosed by <PRE> tags, right? One can make a long line of javascript, css and html code (except the text echoes and such). I used to have a handy DOS tool for this, but it got lost over the years. I can run this as root from a centos linux shell, so no crap with permissions. (And yes, I know, being root is bad. Not for this task though..) The script can be run by me as somescript.sh, like
#!/bin/sh $ perl -pi -e 's|[old_string]|[new_string]|g' [file] Thanks in advance! I'll credit you on my website if you can make this for me. ;-) I love Perl and RegExp. They're my favorite tools!
(This post was edited by Cyré on May 2, 2008, 3:22 PM)
|