I have a file name version.properties with the following data:
major.version=14
minor.version=234
I'm trying to write a grep expression to only put "14" to stdout. The following is not working.
grep "major.version=([0-9]+)" version.properties
What am I doing wrong?
That's progress, but egrep returns "major.version=14" ... I only want the 14.
Try:
sed 's/major\.version=\([0-9]\+\)/\1/'
-or-
sed 's/major\.version=\([0-9]\{1,\}\)/\1/'
-or-
sed -r 's/major\.version=([0-9]+)/\1/'
-or-
awk -F= '$1=="major.version"{print $2}'
I tried all four of those. I'm using cygwin's sed and awk. The first three returned everything after the first equal sign. The awk statement returned nothing at all.
D:\>sed 's/major\.version=\([0-9]\+\)/\1/' version.properties
14
minor.version=234
D:\>sed 's/major\.version=\([0-9]\{1,\}\)/\1/' version.properties
14
minor.version=234
D:\>sed -r 's/major\.version=([0-9]+)/\1/' version.properties
14
minor.version=234
D:\>awk -F= '$1=="major.version"{print $2}' version.properties
---------- Post updated at 02:22 PM ---------- Previous update was at 02:15 PM ----------
gawk works beautifully. Thank you.
---------- Post updated at 02:30 PM ---------- Previous update was at 02:22 PM ----------
Is there any way to get the awk command to print "14.234"?
Oops, that should be:
sed -n 's/major\.version=\([0-9]\+\)/\1/p'
-or-
sed -n 's/major\.version=\([0-9]\{1,\}\)/\1/p'
-or-
sed -nr 's/major\.version=([0-9]+)/\1/p'
---------- Post updated at 20:44 ---------- Previous update was at 20:33 ----------
awk -F= '$1=="major.version"{a=$2}$1=="minor.version"{b=$2}END{print a"."b}'
That's awesome. Thank you!