From: Jonatan Schlag Date: Fri, 18 Aug 2017 11:45:18 +0000 (+0200) Subject: util: add normalize function X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a8d8d2c515148e1ccc411ac4f3b3f039d748af6e;p=people%2Fstevee%2Fnetwork.git util: add normalize function This function remove all non alpha numerical characters from a string and substitute this characters with one - So HELLO%%/$&/)%$%(&&HH becomes hello-hh Signed-off-by: Jonatan Schlag Signed-off-by: Michael Tremer --- diff --git a/src/functions/functions.util b/src/functions/functions.util index f096fbb7..dff0b907 100644 --- a/src/functions/functions.util +++ b/src/functions/functions.util @@ -850,3 +850,9 @@ copy() { return ${EXIT_ERROR} fi } + +normalize() { + local string="$@" + + tr -sc [:alnum:] "-" < <(printf "%s" "${string,,}") +}