Skip to content

Instantly share code, notes, and snippets.

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

Revisions

  1. nateflink revised this gist Feb 17, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions findreplaceosx.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,8 @@
    #!/bin/bash
    #By Nate Flink

    #Invoke on the terminal like this
    #curl -s https://gist.github.com/nateflink/9056302/raw/findreplaceosx.sh | bash -s "find-a-url.com" "replace-a-url.com"

    if [ -z "$1" ] || [ -z "$2" ]; then
    echo "Usage: ./$0 [find string] [replace string]"
  2. nateflink revised this gist Feb 17, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions findreplaceosx.sh
    Original file line number Diff line number Diff line change
    @@ -9,10 +9,10 @@ fi
    FIND=$1
    REPLACE=$2


    #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"
    #needed for byte sequence error in ascii to utf conversion on OSX
    export LC_CTYPE=C;
    export LANG=C;

    #sed -i "" is needed by the osx version of sed (instead of sed -i)
    find . -type f -exec sed -i "" "s|${FIND}|${REPLACE}|g" {} +
    exit 0
  3. nateflink created this gist Feb 17, 2014.
    18 changes: 18 additions & 0 deletions findreplaceosx.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    #!/bin/bash
    #By Nate Flink

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

    FIND=$1
    REPLACE=$2


    #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"
    export LC_CTYPE=C;
    export LANG=C;
    find . -type f -exec sed -i "" "s|${FIND}|${REPLACE}|g" {} +
    exit 0