diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-09-21 19:11:48 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-09-21 19:11:48 +0300 |
commit | d3ebc21eadc5c32edc1ffaa026f51c260c2536fe (patch) | |
tree | e0ca691b6eddf5fd558141c95937e02bef3b0b54 /.bash_utils/text.sh | |
parent | export .appdata/ to another project (diff) | |
download | linux-home-d3ebc21eadc5c32edc1ffaa026f51c260c2536fe.tar.gz linux-home-d3ebc21eadc5c32edc1ffaa026f51c260c2536fe.zip |
add replace_word, swap_files
Diffstat (limited to '.bash_utils/text.sh')
-rw-r--r-- | .bash_utils/text.sh | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/.bash_utils/text.sh b/.bash_utils/text.sh index 5a678ee..cb34073 100644 --- a/.bash_utils/text.sh +++ b/.bash_utils/text.sh @@ -25,3 +25,17 @@ lint() { doslint() { trim "$@" && trimdoseol "$@" && doseol "$@" } + +replace_word() ( + set -o errexit -o nounset -o pipefail + + if [ "$#" -lt 3 ]; then + echo "usage: ${FUNCNAME[0]} OLD NEW PATH [PATH...]" >&2 + return 1 + fi + + local old="$1" + local new="$2" + + shift && shift && sed --binary --in-place "s/\\b$old\\b/$new/g" "$@" +) |