什么是grep regex来提取版本号,如
Version: 3.1.5
* Version: 3.1.5将输出3.1.5
但它不应该抓到喜欢
MIME-Version: 1.0\n这是我的grep命令
grep -ri 'version\s*:\s*[0-9\.]\w*' /home/test/public_html/wp-content/plugins/plugin_name @anubhava woocommerce是一个文件夹。此文件夹下有文件woocommerce.php。
** 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工作
grep -rPo "(^|\s|^\*)+(Version\s*:\s*)\K([0-9]|\.)*(?=\s|$)" /home/test/public_html/wp-content/plugins/woocommerce/发布于 2015-05-07 11:44:40
grep -rPo "(^|\s|^\*)+(Version\s*:\s*)\K([0-9]|\.)*(?=\s|$)" /home/test/public_html/wp-content/plugins/attachments/解释:
-P代表PCRE,-o表示只接受线路的匹配部分。(^|\s)+(Version: )将在开头或一个或多个空白空间匹配Version,然后\K将放弃匹配([0-9]|\.)*将匹配任何数字或. 0或更多次,这是我们想要的发布于 2015-05-07 10:17:02
您可以使用grep -oP (PERL样式regex):
grep -oP 'Version: *\K\S+' file
3.1.5
3.1.5Version: *匹配文字Version:,后面跟着0或更多空格。\K重置匹配信息,\S+匹配版本号。
https://stackoverflow.com/questions/30097978
复制相似问题