Skip to content

Instantly share code, notes, and snippets.

@ip413
Last active May 30, 2021 11:54
Show Gist options
  • Save ip413/80a7f4fb3f6a2f22a20f2f6f5627a0ea to your computer and use it in GitHub Desktop.
Save ip413/80a7f4fb3f6a2f22a20f2f6f5627a0ea to your computer and use it in GitHub Desktop.
#!/bin/bash
# usage-message.sh
if [ $# -eq 0 ]; then
printf "No arguments provided!\n\n"
cat <<EOF
Script accepts three arguments:
- set of characters to generate (more: man tr) (* required)
- number of charaters to generate (* required)
- length of one line (optional, default: value of second argument)
Example:
./generate_random_string.sh 0-3 16 4
3000
3221
2303
2321
Other examples:
- block with 4x4 with charater A only:
...sh A 16 4
- only numbers 0-9:
...sh 0-9 16 4
- only ACGT characters:
...sh ACGT 16 4
- one long line:
...sh xes 100
- online long column (lines with length equal 1):
...sh 0-9a-f 16 1
- special characters:
...sh "\!@%^&*(){}:;'\"<>.,/?" 100 10
- all printable characters:
...sh '[:print:]' 240 20
- hexadecimal digits:
...sh '[:xdigit:]' 100 10
EOF
exit 1
fi
# default value of line length is a number of characters (second argument)
LINE_LENGTH=${3:-$(( $2 ))}
cat /dev/urandom | tr -dc $1 | head --bytes $2 | sed 's/\(.\{'$LINE_LENGTH'\}\)/\1\n/g'
3000
3221
2303
2321
6392575D2B95DB349EE7
eA3a9d6DF64B13df5027
196975eADBa0CE3cBBfc
eABaEa89fA7043b7E5ba
a1aa76FaB179C0b67da8
d2694527a5A1d8CEFb6B
9a30003f8b33F111E69F
Aa6f365a7Fe5c4bf55e7
dF666db8beA63a3d94d5
ba834FeAcdEFfb71d253
3BC7Ea5bf02C2f7BB117
135B6A9c90Fc41cF9DbA
}{$);}_+$)/#'#[@.|++
~$/\'*_~%,!%!"``+({$
~^|^[!)|'<&$|.__!}&[
=+""%;"\!!$;]]%~_#"<
|[*`"}<?(;",#+}>,^_@
*@<.'%,'$/#;,||`}+-)
:<"#.@&_=;`~?}-,:?,-
?'`}:%^(:':-*/)"&/"=
~!_?~:'^\^!&'>@-.*_%
$&<*<\~-:]&)%^,>.;.\
=*}`-$%~-[#>{$}[_`#/
:"!/&&??_);=/!_=<=]~
eeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeee
1001111000
0100010110
0011110000
0001000110
1000101000
0101100100
0000001011
0110101010
1010100100
1010100000
bc15380e67a9c1b026e9087452dfdf8ec8878cc89cd2efb54d72c67be87072d9d67624c276250bc1d7f7d669bc9e6
b
1
1
b
8
6
7
a
a
1
3
b
a
2
a
4
9
d
4
b
3
d
e
8
2
b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment