diff options
author | Einhard Leichtfuß <alguien@respiranto.de> | 2018-12-23 05:58:13 +0100 |
---|---|---|
committer | Einhard Leichtfuß <alguien@respiranto.de> | 2018-12-23 05:58:13 +0100 |
commit | 564a3e2ec83e3883cafe9efd2c6f88144a0835db (patch) | |
tree | f6de746330e59d978ba9767dfc452e9ff5b447d3 | |
parent | 8427f2f38448129c69cc1b0f579296201003909f (diff) |
Simplify basic.sh:replace_line and switch to EREs
EREs: extended regular expressions in contrast to basic regular
expressions (BREs).
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | basic.sh | 32 | ||||
-rwxr-xr-x | update.sh | 15 |
3 files changed, 23 insertions, 26 deletions
@@ -5,3 +5,5 @@ Notify on checksum change. Check for update of freedict-tools. Use updpkgsums from pacman-contrib. + +Increase pkgrel (to be made optional). @@ -3,6 +3,8 @@ # Copyright 2018 Einhard Leichtfuß # +# All methods operate on the file "$tmp". + typeset -a langs langs=( fra-deu deu-fra @@ -31,37 +33,43 @@ function cleanup } trap cleanup EXIT -# $1: string to replace: regular expression +# $1: string to replace: extended regular expression # $2: string to replace with: sed replacement string function replace { - sed -i "s/${1}/${2}/g" "$tmp" + sed -Ei "s/${1}/${2}/g" "$tmp" } -# $1 line to replace: regular expression +# Replace line by a string (possibly including newlines). +# $1 line to replace: extended regular expression # $2 text to replace with: (newline terminated) sed replacement string # $3 removal type: (rm-plus-one|normal) +# `- If $2 is empty, whether to remove only that line or also the one +# following. function replace_line { if test -n "$2" then - cat <(sed "/${1}/,\$ d" < "$tmp") \ - <(echo -n "$2") \ - <(sed "0,/${1}/ d" < "$tmp") \ - > "$tmp_" - mv "$tmp_" "$tmp" + printf '%s' "$2" > "$tmp_" + + sed -Ei " + /${1}/ { + r $tmp_ + d + } + " "$tmp" else if [[ "$3" == rm-plus-one ]] then - sed -i "/${1}/,+1 d" "$tmp" + sed -Ei "/${1}/,+1 d" "$tmp" else - sed -i "/${1}/ d" "$tmp" + sed -Ei "/${1}/ d" "$tmp" fi fi } -# $1 line to delete: regular expression +# $1 line to delete: extended regular expression function delete_line { - sed -i "/${1}/ d" "$tmp" + sed -Ei "/${1}/ d" "$tmp" } @@ -33,25 +33,12 @@ prepare[deu-fra]=\ { cd $_lang sed -Ei \ - -e '"'"'s/(10)(10)(100\>)(.*(1|Eins) mit einem Googol Nullen)/\1^(\2^\3)\4/'"'"' \ + -e '"'"'s/(10)(10)(100\>)(\s+\(10)(Googol.*(1|Eins) mit einem Googol Nullen)/\1^(\2^\3)\4^\5/'"'"' \ -e '"'"'s/(10)([1-9][0-9]*)(.*(1|Eins) mit \2 Nullen)/\1\^\2\3/'"'"' \ -e '"'"'s/(die Zahl 10)(60)/\1^\2/'"'"' \ ${_lang}.tei } ' -prepare[deu-fra-bin]=\ -'prepare() -{ - cd $_lang - dictzip -d ${_lang}.dict.dz - sed -Ei \ - -e '"'"'s/(10)(10)(100\>)(.*(1|Eins) mit einem Googol Nullen)/\1^(\2^\3)\4/'"'"' \ - -e '"'"'s/(10)([1-9][0-9]*)(.*(1|Eins) mit \2 Nullen)/\1\^\2\3/'"'"' \ - -e '"'"'s/(die Zahl 10)(60)/\1^\2/'"'"' \ - ${_lang}.dict - dictzip ${_lang}.dict -} -' . basic.sh |