[GRASS5] Rgb to hex question

I need to transform r:g:b triplets to hexidecimal colors in a bash shell script. Does anyone have an expression that will do that?

Thanks
Michael


C. Michael Barton, Professor of Anthropology
School of Human Evolution and Social Change
PO Box 872402
Arizona State University
Tempe, AZ 85287-2402
USA

Phone: 480-965-6262
Fax: 480-965-7671
www: <www.public.asu.edu/~cmbarton>

I need to transform r:g:b triplets to hexidecimal colors in a bash
shell script. Does anyone have an expression that will do that?

awk with %x or %X:

echo 255 | awk '{printf("%x\n", $1)}'

echo 255:255:255 | tr ':' ' ' | awk '{printf("%X:%X:%X\n", $1, $2, $3)}'

Hamish

From: Hamish <hamish_nospam@yahoo.com>
Sent: Mon, 23 May 2005 12:00:04 +1200

> I need to transform r:g:b triplets to hexidecimal colors in a bash
> shell script. Does anyone have an expression that will do that?

awk with %x or %X:

echo 255 | awk '{printf("%x\n", $1)}'

echo 255:255:255 | tr ':' ' ' | awk '{printf("%X:%X:%X\n", $1, $2,
$3)}'

or, one process saved:

echo 255:128:64 | awk -F: '{printf("%X:%X:%X\n",$1,$2,$3)}'

Daniel.