Skip to content

Instantly share code, notes, and snippets.

@smeagolthellama
Created June 29, 2021 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smeagolthellama/f6f6117042eaeac352988855f81b8dbe to your computer and use it in GitHub Desktop.
Save smeagolthellama/f6f6117042eaeac352988855f81b8dbe to your computer and use it in GitHub Desktop.
#!/bin/bash
# get input from a file given in $1 or stdin if $1 is not provided or -
# while not sorted:
# shuffle lines
# print sorted file
workfile=$(mktemp)
if [[ $# -lt 1 ]] || [[ "$1" = "-" ]]
then
cat > $workfile
else
cp $1 $workfile
fi
while ! sort -C $workfile
do
shuf $workfile -o $workfile
# echo "shuffling"
done
cat $workfile
rm $workfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment