Date Created: Thu 25-Nov-2010

Related Document Categories:

Get my WebSphere Application Server course here >> http://www.themiddlewareshop.com/products/


    Shell script to replace string using korn shell.

    replaceString()
    {
    ###################################################
    # Replace string 1 with string 2.
    # Takes 4 arguments eg:
    # replaceString "Directory" "file" "search_string" "replace_string"
    #
    ###################################################
    if [ $# -ne 4 ]
    then
    print "\nInvalid Entry! Please verify value and try again!\n"
    exit 1
    fi
    cd $1
    if [ $? -ne 0 ]; then
    print "\n\nERROR Could not cd to dir \"${1}\"!!\n\n"
    exit 1
    fi
    if [[ ! -f ${2} ]]; then
    print "\n\nERROR \"${2}\" does not exist in \"${1}\"!!"
    print " - Please re-validate and try again!\n\n"
    exit 1
    fi
    print " Replacing... \"$2\": Replacing \"$3\" with \"$4\" "
    sed -e s!"$3"!"$4"!g $2 > $$_.tmp
    if [ $? -ne 0 ]
    then
    echo "\n\nERROR in sed command during replace substring \"$2\""
    echo " - No changes made.\n\n"
    exit 1;
    fi
    mv $$_.tmp $2

    Get my WebSphere Application Server course here >> http://www.themiddlewareshop.com/products/


Steve Robinson - IBM Champion 2013

About Me

Steve Robinson has been working in IT for over 20 years and has provided solutions for many large-enterprise corporate companies across the world. Steve specialises in Java and Middleware.

In January 2013, I was awarded the prestigous 'IBM Champion' accolade.


Read my books?

IBM WebSphere Application Server 8.0 Administration Guide

IBM WebSphere Application Server 8.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Categories

Other Categories