Skip to content

Instantly share code, notes, and snippets.

@nateflink
Last active November 10, 2024 05:05
Show Gist options
  • Save nateflink/5793139 to your computer and use it in GitHub Desktop.
Save nateflink/5793139 to your computer and use it in GitHub Desktop.

Revisions

  1. nateflink revised this gist Jun 16, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion findreplace.sh
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ FIND=$2
    REPLACE=$3


    if [ -d "${DIRPATH}" ];
    if [ ! -d "${DIRPATH}" ];
    then
    echo "Error: ${DIRPATH} doesn't exist"
    exit 2
  2. nateflink revised this gist Jun 16, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions findreplace.sh
    Original file line number Diff line number Diff line change
    @@ -6,9 +6,9 @@ if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
    exit 1
    fi

    $DIRPATH=$1
    $FIND=$2
    $REPLACE=$3
    DIRPATH=$1
    FIND=$2
    REPLACE=$3


    if [ -d "${DIRPATH}" ];
  3. nateflink revised this gist Jun 16, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion findreplace.sh
    Original file line number Diff line number Diff line change
    @@ -18,5 +18,5 @@ exit 2
    fi

    #sed -i "" is needed by the osx version of sed (instead of sed -i)
    find "${DIRPATH}" -type f | xargs sed -i "" "s|${FIND}|${REPLACE}|g"
    find ${DIRPATH} -type f | xargs sed -i "" "s|${FIND}|${REPLACE}|g"
    exit 0
  4. nateflink revised this gist Jun 16, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion findreplace.sh
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ $FIND=$2
    $REPLACE=$3


    if [ -d ${PATH} ];
    if [ -d "${DIRPATH}" ];
    then
    echo "Error: ${DIRPATH} doesn't exist"
    exit 2
  5. nateflink revised this gist Jun 16, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion findreplace.sh
    Original file line number Diff line number Diff line change
    @@ -18,5 +18,5 @@ exit 2
    fi

    #sed -i "" is needed by the osx version of sed (instead of sed -i)
    find ${DIRPATH} -type f | xargs sed -i "" "s|${FIND}|${REPLACE}|g"
    find "${DIRPATH}" -type f | xargs sed -i "" "s|${FIND}|${REPLACE}|g"
    exit 0
  6. nateflink revised this gist Jun 16, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions findreplace.sh
    Original file line number Diff line number Diff line change
    @@ -6,17 +6,17 @@ if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
    exit 1
    fi

    $PATH=$1
    $DIRPATH=$1
    $FIND=$2
    $REPLACE=$3


    if [ -d ${PATH} ];
    then
    echo "Error: ${PATH} doesn't exist"
    echo "Error: ${DIRPATH} doesn't exist"
    exit 2
    fi

    #sed -i "" is needed by the osx version of sed (instead of sed -i)
    find ${PATH} -type f | xargs sed -i "" "s|${FIND}|${REPLACE}|g"
    find ${DIRPATH} -type f | xargs sed -i "" "s|${FIND}|${REPLACE}|g"
    exit 0
  7. nateflink revised this gist Jun 16, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion findreplace.sh
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ $REPLACE=$3

    if [ -d ${PATH} ];
    then
    echo "error: ${PATH} doesn't exist"
    echo "Error: ${PATH} doesn't exist"
    exit 2
    fi

  8. nateflink created this gist Jun 16, 2013.
    22 changes: 22 additions & 0 deletions findreplace.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #!/bin/bash
    #By Nate Flink

    if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
    echo "Usage: ./$0 [path to files] [find string] [replace string]"
    exit 1
    fi

    $PATH=$1
    $FIND=$2
    $REPLACE=$3


    if [ -d ${PATH} ];
    then
    echo "error: ${PATH} doesn't exist"
    exit 2
    fi

    #sed -i "" is needed by the osx version of sed (instead of sed -i)
    find ${PATH} -type f | xargs sed -i "" "s|${FIND}|${REPLACE}|g"
    exit 0