I’ve cut perhaps a dozen cables, and attached new plugs to them. This isn’t unique to Sonos, but you do need to have care when dealing with electrical cables. They are semi dangerous, and if improperly handled, can either electrocute you, or cause fires.
All that warning aside, I did it mostly for shorter cables, but functionally, it’s the same. In most cases, I’ve replaced my ‘cut’ cables with purchased ones fro various manufacturers, but I have a few still in use.
To be honest, I’d be less inclined to cut the cable and attach a new plug than I would be to cut a small hole in the back of the shelves that I could slither the smaller end of the Sonos cable through. In most cases, the power cords for Sonos are larger at the plug for the wall, but smaller where they plug in to the speaker. That would potentially allow a much smaller notch.
Of course, this is dependent on what the shelves are made of, but I’ve used both large drill bits, and hole cutting bits in various projects. The biggest challenge for me was making the cut at the edge, which has its challenges.
Up to you, of course, but be aware that any modification you may make to the cords would likely void your warranty.
It is usually easier to replace the wall plug end with a store bought replacement plug. If your power plug can be inserted into the wall socket in only one orientation, after you cut the original plug, peal back some outside insulation and note the wire colors routed to each prong of the plug. Duplicate this routing while installing the new plug.
If possible, another approach would be to cut an extension cord and insert this behind the cabinet -- keeping the original power cord intact.
You can also make your own extension cord, buy both ends in the style you like and wire of an appealing color.
Get ends that connect with screws, not just pressure for the best connection.
I like a flat 90 degree angle plug and the smallest socket I can get.