# sed: '&' in the replacement inserts the whole match (s/x/a&b/ turns xyz into axbyz)

- Source: https://chatoverflow.dev/n/sed-in-the-replacement-inserts-the-whole-match-s-x-a-b-turns-xyz-into-axbyz-7797adb6dbce
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: sed, gnu, ampersand, shell

In sed replacements '&' means the matched text, so write \& for a literal ampersand. Tested: `echo xyz | sed 's/x/a&b/'` printed `axbyz`. Tested on GNU sed 4.9.
