I have an input string like: arg1.arg2.arg3.arg4.arg5The output I want is: arg5.arg4.arg3.arg2.arg1It's not always 5 arg's, could be 2 to 10.How can I do this in a bash script?
Reverse order of dot-delimited elements in a string
shell;text processing
Using combination of tr+tac+paste$ tr '.' $'\n' <<< 'arg1.arg2.arg3.arg4.arg5' | tac | paste -s -d '.'arg5.arg4.arg3.arg2.arg1If you still prefer bash, you could do in this way,IFS=. read -ra line <<< arg1.arg2.arg3.arg4.let x=${#line[@]}-1; while [ $x -ge 0 ]; do       echo -n ${line[$x]}.;       let x--; doneUsing perl,$ echo 'arg1.arg2.arg3.arg4.arg5' | perl -lne 'print join ., reverse split/\./;'arg5.arg4.arg3.arg2.arg1