Created
April 17, 2018 23:41
-
-
Save slambert/b26e8a3b30e9ede617c83d7f7038f5c2 to your computer and use it in GitHub Desktop.
This script shuffles the lines of a text file, and then shows a line from that file, one by one, each time it's run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Shuffler Bash Script | |
# Steve Lambert 2018-04-16 | |
# This script shuffles the lines of a text file, and then shows | |
# a line from that file, one by one, each time it's run. | |
# To use this script, create a config file at ~/.shufflerVar | |
# This will hold variables that the script can call each time | |
# it's run. | |
# Create and populate it by running this command: | |
# echo "linenumber=1" > ~/.shufflerVar | |
# Then create your shuffled list by running this command. | |
# Change the file names in the script to the names you'll use. | |
# shuf ordered_list.txt > shuffled_list.txt | |
# this declares where the variables are stored: | |
source ~/.shufflerVar | |
# this displays a line from the shuffled file | |
sed -n $linenumber\p shuffled_list.txt | |
# this iterates the line number | |
linenumber=$((linenumber + 1)) | |
# this saves the new line number to the config file | |
echo "linenumber=$linenumber" > ~/.shufflerVar | |
# this checks if the script has reached the last line of the file | |
# and resets and re-shuffles the list if so. | |
if [[ $linenumber -gt 30 ]]; then | |
echo "linenumber=1" > ~/.shufflerVar | |
gshuf orderedlist.txt > shuffled_list.txt | |
# uncomment the next line for troubleshooting | |
# echo "RESET TO 1" | |
fi | |
# The End |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Still working on this - want to add variables and make it more automatic...