0

I have manifest file which has code for version as follows :

android:versionCode="4240"
android:versionName="4.2.4.0"

I want to write a shell script that changes "4240" and "4.2.4.0" to value passed as command line argument. "sed" command seems right option, I am new to regx or extended regx used by sed command. can anybody suggest me right way to replace value after android:versionCode="

Sachin Giri
  • 189
  • 11

1 Answers1

2

Android manifests are XML, which makes sed a rather terrible tool for handling them. Instead, use xmlstarlet:

xmlstarlet ed -u '/manifest/@android:versionCode' -v 1234 -u '/manifest/@android:versionName' -v 1.2.3.4 manifest

More readably:

xmlstarlet ed -u '/manifest/@android:versionCode' -v 1234 \
              -u '/manifest/@android:versionName' -v 1.2.3.4 manifest

/manifest/@android:versionCode and /manifest/@android:versionName are XPath expressions identifying the attributes you want to change.

Wintermute
  • 42,983
  • 5
  • 77
  • 80