Skip to content

Instantly share code, notes, and snippets.

@wilfm
Created September 14, 2015 17:54
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilfm/6f9b78a0db3553141757 to your computer and use it in GitHub Desktop.
Save wilfm/6f9b78a0db3553141757 to your computer and use it in GitHub Desktop.
Grep Hex Colour Codes from file
#!/bin/bash
#get hex codes in form #fff and #ffffff
#checks to see if not - especially needed on #fff matches
#FIXME: - currently prints trailing character
if [[ ! -a $1 ]]; then
echo File not found
exit 1
fi
sed ':a;N;$!ba;s/\n/ /g' "$1" | grep -o '\#[0-9a-fA-F]\{3\}[^0-9a-fA-F]' | sed 's/[^0-9a-fA-F#]//g' | sort -u
sed ':a;N;$!ba;s/\n/ /g' "$1" | grep -o '\#[0-9a-fA-F]\{6\}[^0-9a-fA-F]' | sed 's/[^0-9a-fA-F#]//g' | sort -u
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment