What will be grep regex to extract version number like
Version: 3.1.5
* Version: 3.1.5
Will output 3.1.5
But It should not catch likes
MIME-Version: 1.0n
Here is my grep command
grep -ri 'versions*:s*[0-9.]w*' /home/test/public_html/wp-content/plugins/plugin_name
@anubhava
woocommerce
is a folder. There is file woocommerce.php
under this folder.
**Content of woocommerce.php
**
* Plugin Name: WooCommerce
* Plugin URI: http://www.woothemes.com/woocommerce/
* Description: An e-commerce toolkit that helps you sell anything. Beautifully.
* Version: 2.3.8
* Author: WooThemes
* Author URI: http://woothemes.com
* Requires at least: 4.0
* Tested up to: 4.2
Working
grep -rPo "(^|s|^*)+(Versions*:s*)K([0-9]|.)*(?=s|$)" /home/test/public_html/wp-content/plugins/woocommerce/
You can use
grep -oP
(PERL style regex):Version: *
matches literalVersion:
followed by 0 or more spaces.K
resets the match information andS+
matches version number.Explanation :
-P
stands for PCRE,-o
for taking only the matched portion of the line(^|s)+(Version: )
will matchVersion
at the start or one or more whitespaces, theK
will then discard the match([0-9]|.)*
will match any digit or.
zero or more times, this is what we wantThe previous token will be followed by either any whitespace character or end of the line