Skip to content

Instantly share code, notes, and snippets.

@earthbound19
Last active January 30, 2016 04:54
Show Gist options
  • Save earthbound19/ecbf7e1b42fb6df51723 to your computer and use it in GitHub Desktop.
Save earthbound19/ecbf7e1b42fb6df51723 to your computer and use it in GitHub Desktop.
Sorts mediaWiki color tables descending in HSL values, using Cygwin (~'nix) sed and sort.
# DESCRIPTION
# Sorts mediaWiki color tables by priority of columns H(ue), S(aturation), L(ightness), descending, using Cygwin (~'nix) sed and sort.
# USAGE
# Call this script with one parameter, being the text file to sort, *inline* -- meaning, THIS WILL DIRECTLY MODIFY whatever text file you pass to it.
## CODE
if [ -a $1_.bk ]
then
echo ~-~-~-~- Backup of input file $1 already exists. Will not execute. Check if the file you passed to this script is already in the state you wish. If not, delete the backup file and run this script against $1 again. ~-~-~-~-
else
echo ~-~-~-~- Backup of input file $1 does not exist. Will create it as $1_.bk before operating on file. ~-~-~-~-
cp $1 $1_.bk
fi
# re http://stackoverflow.com/a/27783094/1397555
# adjusted via a genius breath yon http://stackoverflow.com/a/13522361/1397555 :
# zero-pads two-digit numbers; assumes input has a space after each number we want to manipulate:
sed -i 's/\([^0-9]\)\([0-9]\{2\} \)/\10\2/g' ./$1
# zero-pads one-digit numbers; assumes input has a space after each number we want to manipulate:
sed -i 's/\([^0-9]\)\([0-9]\{1\} \)/\100\2/g' ./$1
# < temp2.txt put spaces back where they got lost for some reason in places before |.
sed -i 's/\([^0-9]\)\(.*[0-9]\{1\}\)\( |\)/\1\2|/g' ./$1
# removes spaces before bars:
sed -i 's/ |/|/g' ./$1
# Sort rows by column priority Hue, Lightness, Saturation.
sort --field-separator='=' -k 6n,6n -k 8n,8n -k 7n,7n ./$1 > temp.txt
rm ./$1
mv ./temp.txt ./$1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment