Search code examples
stringbashawkcharacterscramble

Bash- scramble characters contained in a string


So I have this function with the following output:

    AGsg4SKKs74s62#

I need to find a way to scramble the characters without deleting anything..aka all characters must be present after I scramble them.

I can only bash utilities including awk and sed.


Solution

  • echo 'AGsg4SKKs74s62#' | sed 's/./&\n/g' | shuf | tr -d "\n"
    

    Output (e.g.):

    S7s64#2gKAGsKs4