On Linux, I have a Bash script in which I am using sed
. In this script, I am using substitutions with "sed -i
".
Unfortunately, on MacOS, this version of sed
is not the same as Linux sed
.
I am looking for a way to use a compatible sed on Linux and MacOS, i.e having the same script for both OS.
Could you tell me if using gsed
for both OS instead of sed
allows to have a unique compatible version for this script (where gsed -i
works on both)
Update 1
In my case, on MacOS 10.9.5, I would like to replace the line 2
of a file by the value of a variable. I tried :
a=2
sed -i'' -e "2c\$a" file.dat
but the line is replaced by "$a"
and not the value of a=2
.
What can I try next?
PS: I would like to get a Linux/MacOS portable command line.