[Shell Script] sed: 1: invalid command code J Not working in Mac – Replace old string with a New String in a file

Hi friends,

Recently I was working in Shell script to replace a content of a file. I have used powershell for windows and shell for mac. This is specific to my build server. I was facing one peculiar issue with sed command usage.

Command Used: sed – i ‘s/oldString/newString/g’ filename

Error: sed: 1: invalid command code J on Mac OS

Though i extension is optional in ubuntu, in mac its mandatory to give it. refer the below highlighted screenshot.

sed screenshot

To solve this, I just gave a Empty string Extension like sed – i “”  ‘s/oldString/newString/g’ filename. Voila it solved the issue.

I found it hard to solve this issue as I didnt get any clear pointers. So I thought of creating the page,so it will be helpful for developers.

Advertisement

2 thoughts on “[Shell Script] sed: 1: invalid command code J Not working in Mac – Replace old string with a New String in a file

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s