[ILUG] handy little shell function

From: John P. Looney (jplooney-ilug at domain online.ie)
Date: Mon 07 Feb 2000 - 11:39:48 GMT


 I'd to tear through a library & all my code that used the library and
replace a load of function names that wouldn't clash with another library.

 Here's a handy shell function to do a search & replace on all the files
you send it:

function frep ()
{
    if [ $# -lt 2 ] ; then
        echo "Usage: $0 oldpattern/newpattern [files]"
    else
        old=`echo $1 | cut -d / -f 1`
        new=`echo $1 | cut -d / -f 2`
        shift 1
        echo Replacing $old with $new in $*

    for f in $*
    do
ed - $f << ENDED
g/$old/s//$new/g
w
q
ENDED
    done

    fi
}

Kate



This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:05:22 GMT