From 600f31775ad1dada4b59ab9637e532ac17cdc9ca Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 7 Jan 2021 15:58:53 +0100 Subject: [PATCH] [bin] added dotrev utility --- bin/dotrev | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 bin/dotrev diff --git a/bin/dotrev b/bin/dotrev new file mode 100755 index 0000000..e381165 --- /dev/null +++ b/bin/dotrev @@ -0,0 +1,23 @@ +#!/bin/bash + +# dotrev +# Reverse the order of substrings within a dotted string. +# Example: deboone.nl -> nl.deboone + +while [ -n "$1" ]; do + tmp="$1" + REVHOSTNAME="" + while [ -n "$tmp" ]; do + piece="${tmp##*.}." + tmp="${tmp%.*}" + REVHOSTNAME="${REVHOSTNAME}${piece}" + if ! case "$tmp" in *.*) ;; *) false;; esac; then + REVHOSTNAME="${REVHOSTNAME}${tmp}" + unset tmp + unset piece + break; + fi + done + echo $REVHOSTNAME + shift +done