문제

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

도움이 되었습니까?

해결책

Using awk:

awk -F= '/BUILD_VERSION/{print $2}' input | tr -d "[' ;]"

And with sed:

sed -n "/BUILD_VERSION/s/.*'\([^']*\)'.*/\1/p" input

다른 팁

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top