Sunday, April 28, 2013

Change byte ordering in bash shell - Convert from BGR to RGB format

Say for example BGR color code is BBGGRR; to convert it into RGB format in bash shell:

$ color="BBGGRR"
$ echo ${color:4:2}${color:2:2}${color:0:2}

The format is
${variable:index:length}

This thing could also be used to convert big-endian to little-endian formats.

1 comment:

  1. ... for arbitrarily sized string representations of a number that's needed in little endian

    echo 1234abcd | grep -o .. | tac | echo "$(tr -d '\n')"
    cdab3412

    ReplyDelete