Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 需要从bash中的字符串获取子字符串_Regex_Bash_Grep - Fatal编程技术网

Regex 需要从bash中的字符串获取子字符串

Regex 需要从bash中的字符串获取子字符串,regex,bash,grep,Regex,Bash,Grep,我正在尝试在bash中获得Atom版本。Thid regex正在工作,但我需要string中的一个子字符串,它将提供grep。如何从该字符串获取版本 <span class="version">1.34.0</span> curl https://atom.io/ | grep 'class="version"' | grep '[0-9]\+.[0-9]\+.[0-9]\+' 1.34.0 卷曲https://atom.io/ |grep'class=“versio

我正在尝试在bash中获得Atom版本。Thid regex正在工作,但我需要string中的一个子字符串,它将提供grep。如何从该字符串获取版本

<span class="version">1.34.0</span>

curl https://atom.io/ | grep 'class="version"' | grep '[0-9]\+.[0-9]\+.[0-9]\+'
1.34.0
卷曲https://atom.io/ |grep'class=“version”'| grep'[0-9]\+[0-9]\+[0-9]\+[0-9]\+'

您可以通过使用
cut
命令并添加各自的分隔符来实现这一点;在您的情况下,这将是
awk

$ curl ... | awk -F'[<>]' '/class="version"/{print $3; exit}'
$curl…|awk-F'[]'/class=“version”/{print$3;exit}

Note的可能重复如果您有Gnu grep,您可以对perl风格的正则表达式使用-P选项,而-o选项只打印与模式匹配的内容。请尝试将此作为管道中的最后一个命令:
grep-oP“\d+\.\d+\.\d+”
Oh,注意将点转义为文字点,否则表示任何字符。
$ curl ... | awk -F'[<>]' '/class="version"/{print $3; exit}'