2

I don't understand Darwin vs. CentOS. This is not the first command that has failed me. The exact command works fine on CentOS but not on Darwin. I read the man page for sed ON MY MBP and in theory, it should work on MBP.

Can someone tell me what the correct syntax for using sed on Darwin is? The exact same command works on a CentOS server. However, all of the files I need to run sed with are stored on my local development laptop which is a MBP. I don't want to copy all my test files to our remote CentOS server, just to run this stupid cmd that should work in the first place.

This is the cmd I'm trying to run on my MBP:

sed -i 's/instance=ge/blah/g' 100usr_defSemaAvail_mult_12hr.jmx

The error on the MBP says this

sed: 1: "100usr_defSemaAvail_ ...": invalid command code u

Thanks in advance for helping this frustrated soul.

Classified
  • 5,759
  • 18
  • 68
  • 99
  • @devnull, thx for pointing me to an existing question/answer. i've voted to close this question too. rage and poor google search skills didn't help me find this answer. sorry about this. – Classified Mar 20 '14 at 00:51

1 Answers1

5

In the BSD version of sed used on the Mac, the -i option requires an argument containing the suffix to use for the backup file. If you don't want to create a backup file, you have to provide an empty argument:

sed -i '' 's/instance=ge/blah/g' 100usr_defSemaAvail_mult_12hr.jmx

The command you entered specified s/instance=ge/blah/g as the suffix, and 100usr_defSemaAvail_mult_12hr.jmx as the editing commands.

This is different from GNU sed used on Linux, which expects the suffix to be attached to the -i option (e.g. -i.bak). So -i by itself means no backup file.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • I suspect it's actually BSD vs GNU, not Mac vs everyone else (unless everyone else now uses GNU sed). – Barmar Mar 20 '14 at 00:47
  • Dang it, THAT'S it. the man pg said if a 0 length extension isn't given, there's no backup. i didn't know you had to type in '' b/c CentOS didn't require me to. I am going to ram my head into a wall now. Thanks so much for the quick reply. – Classified Mar 20 '14 at 00:48