What will be grep regex to extract version number like   Version: 3.1.5 * Version: 3.1.5Will output   3.1.5But It should not catch likesMIME-Version: 1.0\nHere is my grep commandgrep -ri 'version\s*:\s*[0-9\.]\w*' /home/test/public_html/wp-content/plugins/plugin_name not workinggrep -Po (^|\s)+(Version: )\K([0-9]|\.)*(?=\s|$) /home/test/public_html/wp-content/plugins/woocommerce/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.2Workinggrep -rPo (^|\s|^\*)+(Version\s*:\s*)\K([0-9]|\.)*(?=\s|$) /home/test/public_html/wp-content/plugins/attachments/
To grep version number from Wordpress plugin folder
grep;regular expression
You can use:grep -Po (?<=Version: )([0-9]|\.)*(?=\s|$)If you have MIME-Version: 1.0 instead of MIME-Version: 1.0\n:grep -Po (^|\s)+(Version: )\K([0-9]|\.)*(?=\s|$)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 wantThe previous token will be followed by either any whitespace character or end of the lineTest:$ cat file.txt  Version: 3.1.5 * Version: 3.1.5MIME-Version: 1.0\n$ grep -Po (?<=Version: )([0-9]|\.)*(?=\s|$) file.txt 3.1.53.1.5$ cat file.txt Version: 3.1.5 * Version: 3.1.5MIME-Version: 1.0$ grep -Po (^|\s)+(Version: )\K([0-9]|\.)*(?=\s|$) file.txt 3.1.53.1.5