Advertisement
This is comment for paste
BASH Shuffle and Match up Lists
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- #usage team_up.sh FILE
- [[ $# -eq 0 ]] && printf "\nERROR: You must provide a file for the script to work.\n\n" 1>&2 && exit 1
- readarray -t names < <(sort -R $1) #create an array with each line of the file; -t strips the new line character
- max=0 #used for proper formatting later in the script
- for ((i=0; i<${#names[@]}; i+=2)) #i as in index; this way we get the even line numbers.
- do
- if ((${#names[i]} > max)); then
- max=${#names[i]}
- else
- max=$max #get the string lenghth of the longest name. Usage later in printf.
- fi
- done
- for ((i=0; i<${#names[@]}; i+=2)); do
- printf -- "%-${max}s %s\n" "${names[i]}" "${names[i+1]}" #i+1, this way we get the odd line numbers
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement