2

I want to get the versionName from the AndroidManist.xml file with a shell command. I've been trying to use grep and with:

 grep versionName ./AndroidManifest.xml

I'm getting this line:

android:versionName="1.0">

Is it possible to narrow it down to 1.0 somehow?

Thanks in advance

2 Answers 2

3

Try this :

perl -e 'while($line=<>) { if ($line=~ /versionName\s*=\s*"([^"]+)"/) { print "$1\n";}}' <AndroidManifest.xml

You may want to put this into a file :

Ex: VersionNum.pl

#!/usr/bin/perl

#get the filename from command line
$file = shift or die;

#open the file and read it into $lines var
open(IN,$file) or die;
$lines=join("",<IN>); 
close(IN);

#search the $line var for match and print it
if ($lines =~ m/android:versionName\s*=\s*"([^"]+)"/mgs)  {
   print "$1\n";
}

Then simply chmod 755 VersionNumber.pl and use it with VersionNumber.pl AndroidManifest.xml

Sign up to request clarification or add additional context in comments.

Comments

2

A shorter version could be derived from your original suggestion:

grep versionCode AndroidManifest.xml | sed -e 's/.*versionName\s*=\s*\"\([0-9.]*\)\".*/\1/g'

2 Comments

grep versionCode AndroidManifest.xml | cut -d\" -f2
One thing to think about is when you have versionCode="" and versionName="" both on the same line. either one preceded by the other.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.