Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #print odd numbered lines
- sed -n 1~2p names.lst
- #print even numbered lines
- sed -n 2~2p names.lst
- #randomize name list
- random="$(sort -R names.lst)"
- echo $random
- #set Internal Field Separator to space
- IFS=" "
- echo $random
- #put even names and odd names into lists
- odds="$(echo $random|sed -n 1~2p)"
- evens="$(echo $random|sed -n 2~2p)"
- #print name list team up
- paste <(echo "$odds") <(echo "$evens")
- #Formatted
- paste <(echo "$odds") <(echo "$evens")|column -t
Advertisement
Comments
-
- #! /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
Add Comment
Please, Sign In to add comment
Advertisement