Finding (and replacing) colours in an SVG (vector image) file

I wanted to replace some colours in an image.  The source file is an SVG file of some complexity, but it only contains a few distinct colours.  I thought the easiest way to replace the colours would be to use one of the functions in Inkscape, a great open-source vector image editor.  However, I opened it and didn’t see an obvious way, so decided to do it at the command-line.  It might work for you, too, if you’re running a unix-like operating system (e.g. Linux, Mac OS).

Step 1: Find a list of all of the colours used in your image:

tr '"' '\n' < filename.svg |grep '#'|sort|uniq

This will output something like this:


Step 2: Replace the colour you don’t like, using a text editor or the command line.  I used nano (ctrl-\ does find-and-replace) but you could do it at the command line if you only have one replacement to do:

tr '#261010' '#FFFFFF' < old.svg > new.svg