I need to replace the versionName in a xml file from a shell script using sed.
Replace not-"
, like this:
sed -i .old '/android:versionName/ s/="[^"][^"]*"/="NEW VERSION NAME"/' AndroidManifest.xml
sed 's/\([[:blank:]]android:versionName="\)[^"]*"/\1Your New Value"/' YourFile
android:versionName
will be changed[[:blan:k]]
by \(^\|[[:blank:]]\)
(and a -i
if direct modification avoiding temporary file)Considering the nature of xml and the version number, it is actually very safe to use a simpler command:
sed -i '/versionName/s/".*"/"NEW VERSION NAME"/' AndroidManifest.xml
P.S. in my opinion, it is very important to be able to simplify your shell script based on specific circumstances and reasonable assumptions.