awk - replace number of string length from search and replace for a serialized array

Hello,
I really would appreciate some help with a bash script for some string manipulation on an SQL dump:

I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump.
This is quite easy with sed:

sed -e 's#sites/[a-zA-Z0-9]*/files#sites/SOMETHINGELSE/files#g' dump.sql > dump_manipulated.sql

ok, my problem is that some of these strings are within an serialized array (from php) and some not.

see part of the sql dump:

INSERT INTO `variable` VALUES ('color_garland_logo','s:51:\"sites/default/files/color/garland-db56b801/logo.png\";');
INSERT INTO `variable` VALUES ('color_garland_stylesheets','a:2:{i:0;s:52:\"sites/default/files/color/garland-db56b801/style.css\";i:1;s:56:\"sites/default/files/color/garland-db56b801/style-rtl.css\";}');
INSERT INTO `menu_router` VALUES ('sites/default/files/imagecache','','','1','a:0:{}','imagecache_cache','a:0:{}',15,4,'','sites/default/files/imagecache','','t','',4,'','','',0,'');

The ones that are within the serialized arrays have something like s:51: before the actual string. the number refers itself to the length of the following string. When changing the string usually the length changes as well and php doesn't let me unserialize the array properly.

I guess that I'd need to write some lines with awk to count on the new string and to overwrite the number. But I doesn't really have a clue about awk. Is there a friendly person that would help me out?

Thank you,
Michael

Er, I think you can get it done by removing the serializing code from such strings. I You can always try it:

sed -e 's#s:[0-9][0-9]*:\"sites/[a-zA-Z0-9]*/files#\"sites/SOMETHINGELSE/files#g'

If it doesn't work, Perl might be easier for the job. Something like this might work:

 perl -p -e 's#sites/[a-zA-Z0-9]*/files#sites/SOMETHINGELSE/files#g && s#s:\d+(:\\")(.*?)(\\")#"s:".length($2).$1.$2.$3#e;'

The first half looks just like your sed script. The second half works IF the first half replaced something and then it
replaces all sequences of s:<number>:\"string\" with s:<length-of-string>:\"string\".