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.0\n
Here is my grep command
grep -ri 'version\s*:\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|^\*)+(Version\s*:\s*)\K([0-9]|\.)*(?=\s|$)" /home/test/public_html/wp-content/plugins/woocommerce/
You can use grep -oP
(PERL style regex):
grep -oP 'Version: *\K\S+' file
3.1.5
3.1.5
Version: *
matches literal Version:
followed by 0 or more spaces. \\K
resets the match information and \\S+
matches version number.
grep -rPo "(^|\s|^\*)+(Version\s*:\s*)\K([0-9]|\.)*(?=\s|$)" /home/test/public_html/wp-content/plugins/attachments/
Explanation :
-P
stands for PCRE, -o
for taking only the matched portion of the line
(^|\\s)+(Version: )
will match Version
at the start or one or more whitespaces, the \\K
will then discard the match
([0-9]|\\.)*
will match any digit or .
zero or more times, this is what we want
The previous token will be followed by either any whitespace character or end of the line
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.