Skip to content

Instantly share code, notes, and snippets.

@zivester
Last active February 1, 2019 18:31
Show Gist options
  • Select an option

  • Save zivester/fe01ad5160e8912b6b65009b2a043982 to your computer and use it in GitHub Desktop.

Select an option

Save zivester/fe01ad5160e8912b6b65009b2a043982 to your computer and use it in GitHub Desktop.
sed convert hex color codes to rgb
#!/bin/bash
#
# no-hex-clean.sh
#
# Usage: Pipe hex codes to this script
#
# e.g.
#
# $ cat *.svg | perl -ne '/(#[0-9A-Fa-f]{6})/g && print "$1\n"' | sort | uniq | ./no-hex-clean.sh
#
function rgbToHex {
hex=`printf \#%02X%02X%02X "$@"`
}
function hexToRgb {
rgb=`printf "%d,%d,%d" 0x${hex:1:2} 0x${hex:3:2} 0x${hex:5:2}`
}
while read hex;
do
hexToRgb
echo sed -i "s/$hex/rgb($rgb)/gi"
sed -i "s/$hex/rgb($rgb)/gi" *.svg
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment