Basically i am creating an update checker for emesene on osx. I need to find out the version number from inside this file: http://emesene.svn.sourceforge.net/viewvc/emesene/trunk/emesene/Controller.py
The version number is found at self.VERSION = 'version' in the file e.g. self.VERSION = '1.6.3'
The version number then needs to be saved in a file
Is this possible using grep?
grep "self.VERSION = '.*'" Controller.py | cut -d "'" -f 2 > file
If you can use sed(1), then you can extract it with a single command:
sed -n "s/.*self\.VERSION = '\([^']*\)'.*/\1/p" Controller.py > file
you can use awk,
$ awk -F"['-]" '/VERSION[ \t]=/{print $2}' Controller.py
1.6.3
Related
I want to get version number of tomcat.tar.gz file like this
read -p echo " Enter Version (8 or 9)" version
version8=$(printf -- '%s\n' * | grep -oP 'apache-tomcat-$version\K.*(?=\.tar\.gz)')
version9=$(printf -- '%s\n' * | grep -oP 'apache-tomcat-$version\K.*(?=\.tar\.gz)')
echo $version8 #or better $version${version}, but that doesn't work, too
depending on which version the user entered, I will receive the version number from the gz-file in the current folder.
Example:
in my folder are two tar.gz
apache-tomcat-8.5.78.tar.gz
apache-tomcat-9.0.56.tar.gz
Starting the script:
Enter Version (8 or 9): 8
output should be: 8.5.78
With the above code I am getting nothing. What's wrong with it? I suspect it is due to the variable (version) within a variable (version8). How is it syntactically correct?
I have this working with awk if you are interested, as follows:
read -p "Enter Version (8 or 9) " version
ls *.gz | awk "{split(\$0,a,\"-\"); split(a[3],b,\".\"); split(a[3],c,\".tar\"); if (b[1] == \"$version\") {print c[1]}}"
I am using Jira to create a bitbucket branch for releases. As part of the build process I need to extract the release number from the branch name.
An earlier part of the build dumps the whole branch name to a text file. The problem I'm having is removing all the text before the build number.
An example branch name would be:
release/some-jira-ticket-343-X.X.X
Where X.X.X is the release number e.g. 1.11.1 (each of X could be any length integer).
My first thought was to literally just select the last 3 characters with sed, however as X could be any length this won't work.
Another post (Removing non-alphanumeric characters with sed) suggesting using the sed alpha class. However this won't work as the jira ticket ID will have numbers in.
Any ideas?
You can remove all characters up to last -:
$ sed 's/.*-//' <<< "release/some-jira-ticket-343-1.11.2"
1.11.2
or with grep, to output only digits and dots at the end of the line:
grep -o '[0-9.]*$'
awk solution,
$ awk -F- '{print $NF}' <<< "release/some-jira-ticket-343-1.11.1"
grep solution,
grep -oP '[0-9]-\K.*' <<< "release/some-jira-ticket-343-1.11.1"
use string operators:
var="release/some-jira-ticket-343-2.155.7"
echo ${var##*-}
print:
2.155.7
Awk solution:
awk -F [-.] '{ print $5"."$6"."$7 }' <<< "release/some-jira-ticket-343-12.4.7"
12.4.7
Set the field delimiter to - and . and then extract the pieces of data we need.
How to get only the version from set of lines?
These are the lines inn flat file:
./org.jamon/jamon-runtime/jars/jamon-runtime-2.3.1.jar
./org.apache.ftpserver/ftplet-api/bundles/ftplet-api-1.0.0.jar
./org.clojars.jasonjckn/kafka_2.9.2/jars/kafka_2.9.2-0.7.2-test1.jar
./org.apache.ftpserver/ftpserver-deprecated/jars/ftpserver-deprecated-1.0.0-M2.jar
./org.codehaus.jettison/jettison/bundles/jettison-1.1.jar
./stax/stax-api/jars/stax-api-1.0.1.jar
Output:
2.3.1
1.0.0
0.7.2-test1
1.0.0-M2
1.1
For a sed solution:
sed 's/.*-\([0-9][0-9.]*[^\/]*\)\.jar$/\1/'
Explanation:
Replace: anything + hyphen + revision + ".jar" with just the revision, where:
The the revision is identified as: starts with number, followed by numbers or dots, followed by any text except slash /, and is preceded by a hyphen -.
".jar" must be at the end-of-line.
Using GNU grep with -P option (PCRE regex for look ahead and behind):
grep -oP '(?<=-)[0-9.]+[-[:alnum:]]*(?=\.jar)' file
2.3.1
1.0.0
0.7.2-test1
1.0.0-M2
1.1
1.0.1
As suggested cbuckley in the comments more generic way of saying it would be (will work if you files have extensions other than .jar:
grep -oP '(?<=-)[\d.]+[-\w]*(?=\.\w+)' file
Here you go:
awk -F/ '{n=split($NF,a,"-");if (a[n-1]~/[0-9.]+/) a[n]=a[n-1]"-"a[n];sub(/\.jar$/,"",a[n]);print a[n]}' file
2.3.1
1.0.0
0.7.2-test1
1.0.0-M2
1.1
1.0.1
If you have gnu grep use the Jaypal's solution :), this awk should work on most system.
Simple solution is
grep -Po "(?<=-)\d[^/]*(?=\.jar$)"
I need to write a shell script that does the following:
In a given folder with files that fit the pattern: update-8.1.0-v46.sql I need to find the maximum version
I need to write the maximum version I've found into a configuration file
For 1, I've found the following answer: Shell script: find maximum value in a sequence of integers without sorting
The only problem I have is that I can't get down to a list of only the versions,
I tried:
ls | grep -o "update-8.1.0-v\(\d*\).sql"
but I get the entire file name in return and not just the matching part
Any ideas?
Maybe move everything to awk?
I ended up using:
SCHEMA=`ls database/targets/oracle/ | grep -o "update-$VERSION-v.*.sql" | sed "s/update-$VERSION-v\([0-9]*\).sql/\1/p" | awk '$0>x{x=$0};END{print x}'`
based on dreamer's answer
you can use sed for this:
echo "update-8.1.0-v46.sql" | sed 's/update-8.1.0-v\([0-9]*\).sql/\1/p'
The output in this case will be 46
grep isn't really the best tool for extracting captured matches, but you can use look-behind assertions if you switch it to use perl-like regular expressions. Anything in the assertion will not be printed when using the -o flag.
ls | grep -Po "(?<=update-8.1.0-v)\d+"
46
I am trying to get Update queries from a list of files using this script.I need to take lines containing "Update" alone and not "Updated" or "UpdateSQL"As we know all update queries contain set I am using that as well.But I need to remove cases like Updated and UpdatedSQL can anyone help?
nawk -v file="$TEST" 'BEGIN{RS=";"}
/[Uu][Pp][Dd][Aa][Tt][Ee] .*[sS][eE][tT]/{ gsub(/.*UPDATE/,"UPDATE");gsub(/.*Update/,"Update");gsub(/.*update/,"update");gsub(/\n+/,"");print file,"#",$0;}
' "$TEST" >> $OUT
This seems more readable to me without all the [Uu] and it doesn't require grep:
{ line=tolower($0); if (line ~ /update .*set/ && line !~ /updated|updatesql/) { gsub ...
you can try using grep first, (and i assume you are on Solaris.)
grep -i "update.*set" "$TEST" | egrep -vi "updatesql|updated" | nawk .....