If you are looking for the epic motorcycle journey blog that I've written, please see the Miles By Motorcycle site I put together. 
  • Subscribe to this RSS Feed
  • Ian
    One-liner for multiline substitutions
    09/23/2004 11:41AM
    I was asked to replace certain HTML code from a bunch of files with a PHP include statement, so that the code could be managed in just one file. The code spanned several lines and required multiline substitution, e.g.

    perl -pi -e '$/=undef; s|$pattern|$replacement|smg'

    I applied this to over a thousand files in just a few seconds as:

    # find . -type f -name "*.php" -exec perl -pi -e '$/=undef; s|$pattern|$replacement|smg' {} \;

    Here's an example:

    # in this case, we're replacing:
    # ------------------------------
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link rel="stylesheet" type="text/css" href="<?php echo $local{url_base_local}; ?>/textfonts.css">

    <SCRIPT LANGUAGE="JavaScript">
       function second_window(targetUrl) {
    var win = window.open("", "PrintWin", "status=yes,scrollbars=yes,directories=yes,location=yes,menubar=yes,toolbar=yes,resizable=yes,screenX=200,screenY=5,left=200,top=5", true);
       win.location = targetUrl;
       var browser = navigator.appName;
          if ( (browser = 'Netscape') && (_version > 1.0) ) {
       // -->

    # with:
    # -----
    include "$include_dir/head_meta.php";
    include "$include_dir/js_second_window.php";

    perl -pi -e '$/=undef;
    > $repl=qq{n<?phpninclude "$include_dir/head_meta.php";ninclude "$include_dir/js_second_window.php";n?>n};
    > s|<meta http.*</SCRIPT>|$repl|smg' tt2.php

  • HTML Entity Test
    09/23/2004 11:23AM
    <script language="javascript">
  • Inexpensive quad 72 U320 Array.
    09/22/2004 12:08PM
    Ian forwarded me a link to a company that's selling a quad external SCSI (U320) SCA disk array with bids starting at 499.


  • "Argument list too long" - deleting large number of files in a directory
    09/21/2004 3:51PM
    I was asked a question today about how do you delete a very large number of files in a directory under Linux when you get a :

    /bin/rm: Argument list too long

    What happens when you do a

    rm *

    in a directory is that first the * gets expanded to the list of files in the directory. There is a limit to how long this argument list can be. It is possible to have a directory that has so many files in it that you get the Argument list too long error.

    In this case you need to do one "rm" for each file in the directory as in:

    for i in `ls`; do rm -f $i; done


    This will delete every file in the current directory. Use at your own risk.
  • Tuberculosis May Become A Global Threat Again
    09/20/2004 1:02PM
    Serious bummer. Doom 'n gloom in the extreme.

    As seen on slashdot.org, Tuberculosis may become a much bigger problem.