sed on Mac OS versus Linux

I'm trying to replace space with inderscore on Mac OS X 10.6.3

sed -i 's/ /_/g' somefile
sed: 1: "hsa_mirbase.fa": extra characters at the end of h command

This works perfectly fine on Linux.
Thank you
Joseph Dhahbi

Hi.

From the OSX man page for SED:

-i extension
  Edit files in-place, saving backups with the specified extension.

So, for example:

sed -i.bak 's/ /_/g' somefile

(I guess that the extension is optional on Linux, but may be provided (will check!))

(actually, without checking too much, according to the man page here, it is optional)

(actually #2, the OSX man page is rubbish! It suggests that it is optional, but complains when it's not given)

-i extension
             Edit files in-place, saving backups with the specified extension.  If a zero-length extension is given,
             no backup will be saved.  It is not recommended to give a zero-length extension when in-place editing
             files, as you risk corruption or partial content in situations where disk space is exhausted, etc.
1 Like

Thank you for your help

SED on OS X is the BSD version (certainly is on OS X 10.6.4).

I have found that GNU versions of UNIX utilities often have far more options available to them, the danger is that if you know the extra options, you'll miss them on BSD based systems.

Ben