I have a file like
public class Constants {
public static final String PACKAGE_VERSION = '1.24.0.1';
}
I am executing the script
sed -E "/PACKAGE_VERSION/s/\'([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\'/\'1.24.0.2\'/g" force-app/main/default/classes/Constants.cls > temp.cls
mv temp.cls force-app/main/default/classes/Constants.cls
to replace the string '1.24.0.1' with '1.24.0.2'
Is this possible to do this with one line? Should I use awk
instead of sed
to inline edit the file?
When I try to execute a command
sed -iE "/PACKAGE_VERSION/s/\'([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\'/\'1.24.0.3\'/g" force-app/main/default/classes/Constants.cls
file Constants.clsE is created instead of inline modification to the current file and the new file doesn't have substitution.
When I try to execute a command
sed -Ei "/PACKAGE_VERSION/s/\'([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\'/\'1.24.0.3\'/g" force-app/main/default/classes/Constants.cls
I receive an error
sed: 1: "force-app/main/default/ ...": invalid command code f
I want the script to work both in MacOS and Linux without changing the script.
I tried to use awk
, but I don't understand how can I make it inline editing the file?
When I try to execute the following
awk -v v="$version" '/PACKAGE_VERSION/{gsub(/[0-9]+(.[0-9]+){3}/,v)}1' force-app/main/default/classes/Constants.cls > force-app/main/default/classes/Constants.cls
this makes my file blank
-i
option to theirsed
years after FreeBSD. – Stéphane Chazelas May 31 '22 at 15:59