Using sed
$ s="32=rtys;54tyu;45_fd;62=xyz;fdg"
$ sed -E 's/;/\n/g; s/\n[0-9]+=/;&/g; s/\n//g' <<<"$s"
32=rtys54tyu45_fd;62=xyzfdg
This works in three steps:
s/;/\n/g
replaces all semicolons with newlines. Because, by default, sed takes input one line at a time, the pattern space will never have a newline to start. Thus will be no confusion.
s/\n[0-9]+=/;&/g
puts a semicolon in front of any newline followed by a number followed by an equal sign.
s/\n//g
removes all newlines.
The above was tested on GNU sed. For BSD/OSX, some changes will likely be needed. The following might work:
sed -E $'s/;/\n/g; s/\n[0-9]+=/;&/g; s/\n//g' <<<"$s"
Using awk
$ s="32=rtys;54tyu;45_fd;62=xyz;fdg"
$ awk -F\; '{$1=$1; for (i=2;i<=NF;i++) if ($i~/^[0-9]+=/) $i=";"$i} 1' OFS="" <<<"$s"
32=rtys54tyu45_fd;62=xyzfdg
This works by using ;
as the field separator on input and the empty string as a field separator on output. This would remove all ;
except that we check each field: if a field begins with number+=
, we add a semicolon to the beginning of that field.