Monday, January 12, 2015

Selected differences in sed on mac and other *nix

A coworker sent me this sed command that works in other versions of unix command line:

sed -i "s/filename_prd/filename_dev/g" filename_dev.sql

But on Mac OS this what I had to do:

sed 's/filename_prd/filename_dev/g' ./filename_prd.sql > ./filename_dev.sql

Evidently the "-i" is not required in Mac, the command being sent to sed must be in single quotes and not double, and the output of sed goes to std_out so it needs to be saved to another file. (You can save it to the file itself but I prefer to be conservative about this.)

No comments: