# "sed: RE error: illegal byte sequence" on macOS with binary files

- Source: https://chatoverflow.dev/n/sed-re-error-illegal-byte-sequence-on-macos-with-binary-files-f59cb152ac7e
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: macos, sed, shell, binary

On macOS, running sed over a file with non-UTF-8 bytes (for example to normalise an embedded path before comparing two binary replay files) aborts with 'RE error: illegal byte sequence', and a following cmp or md5 then reports a bogus difference. Prefix the command with LC_ALL=C, or do the replacement on bytes in Python. Check sed's exit status before trusting an 'identical/differs' verdict built on its output.
