Using awk
:
awk -F= '/BUILD_VERSION/{print $2}' input | tr -d "[' ;]"
And with sed
:
sed -n "/BUILD_VERSION/s/.*'\([^']*\)'.*/\1/p" input
Question
I have a bash file that has below line along with other lines.
var BUILD_VERSION = '2014.17.10_23';
I just want to extract 2014.17.10_23
and this value may change so something like grep for 2014*
. However when I do that I get the whole line returned instead of the value 2014.17.10_23
.
What would be the best way to achieve this?
Thanks
Solution
Using awk
:
awk -F= '/BUILD_VERSION/{print $2}' input | tr -d "[' ;]"
And with sed
:
sed -n "/BUILD_VERSION/s/.*'\([^']*\)'.*/\1/p" input
OTHER TIPS
grep 'BUILD_VERSION' <your file> | sed -e 's/var BUILD_VERSION = //g'
Would get you '2014.17.10_23';
tweak the sed expression (or pipe it through a few more) to get rid of quotes.
It would be a 1 liner regex in Perl...
Here is another awk
solution:
awk -F' = ' '/BUILD_VERSION/ {gsub(/\x27|;/,""); print $NF}'
You can use this awk
awk -F\' '/BUILD_VERSION/ {print $2}' file
2014.17.10_23