The issue comes from the fact that the sed
shipped with macOS is not the GNU sed
, but rather a form of a BSD sed
. Not all arguments as well as syntaxt in general are similar. Let's quickly fix this by using Homebrew.
In my particular case the "illegal offset" issue occured when I wanted to patch a Windows executable in macOS Sequoria.
This is the command I have used:
~/DOSGAMES/LOLG/ sed -b -i -e "s/24\(M,Swap\)/32\1/" LOLG.EXE
Unfortunately this was unsuccessful and returned with:
sed: illegal option -- b
usage: sed script [-EHalnru] [-i extension] [file ...]
sed [-EHalnu] [-i extension] [-e script] ... [-f script_file] ... [file ...]
Solution
Let's use GNU version of the sed command. The easiest approach is to pull it via Homebrew package manager, follow this link if Homebrew is not present on your macOS. Pull it by typing:
brew install gnu-sed
Once installed, you can validate it by calling which gsed
.
Finally swap sed with gsed and carry on with your original command:
gsed -b -i -e "s/24\(M,Swap\)/32\1/" LOLG.EXE
This should do the trick and your file should be modified accordingly to the given arguments. By the way - always remember to backup your target file:
cp LOLG.EXE LOLG.EXE_ORIG
This is it.