Last active
February 1, 2019 18:31
-
-
Save zivester/fe01ad5160e8912b6b65009b2a043982 to your computer and use it in GitHub Desktop.
sed convert hex color codes to rgb
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/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