Skip to content

Instantly share code, notes, and snippets.

@sehrgut
Last active December 21, 2015 13:58
Show Gist options
  • Save sehrgut/6315894 to your computer and use it in GitHub Desktop.
Save sehrgut/6315894 to your computer and use it in GitHub Desktop.
For OS X and other platforms where you don't have GNU sort, but want a quick way to shuffle lines. This has been done many times before, but most implementations I've seen don't deal equally with filename arguments and stdin.
#!/bin/bash
# Licensed under any of GPLv2, MIT, and BSD 2-clause licenses
(
if [[ $1 ]]; then
while [[ $1 ]]; do
cat $1
shift
done
else cat
fi
) |\
while read line; do
echo "${RANDOM}~$line";
done | sort | sed -E 's/^[0-9]+~//'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment