使用shell命令提取版本

使用shell命令提取版本,shell,awk,sed,grep,cut,Shell,Awk,Sed,Grep,Cut,我正在尝试使用shell命令从下面提到的URL中提取版本,比如,grep,awk,sed,cut,这是最合适的 https://abcd/efgh/1.1.3/hijkl/mnop https://abcd/efgh/hijkl/2.3.4.5/mnop https://abcd/3.4/efgh/hijkl/mnop 我希望从URL中单独提取版本(带点的数字),位置可能会有所不同,如上面的示例所示。寻找建议 预期产出为: 1.1.3 2.3.4.5 3.4 您可以使用此gr

我正在尝试使用shell命令从下面提到的URL中提取版本,比如,grep,awk,sed,cut,这是最合适的

https://abcd/efgh/1.1.3/hijkl/mnop    
https://abcd/efgh/hijkl/2.3.4.5/mnop    
https://abcd/3.4/efgh/hijkl/mnop
我希望从URL中单独提取版本(带点的数字),位置可能会有所不同,如上面的示例所示。寻找建议

预期产出为:

1.1.3
2.3.4.5
3.4

您可以使用此
grep

grep -Eo '[0-9]+(\.[0-9]+)+' file

1.1.3
2.3.4.5
3.4

我会使用GNU
AWK
如下方式,让
file.txt
内容

https://abcd/efgh/1.1.3/hijkl/mnop    
https://abcd/efgh/hijkl/2.3.4.5/mnop    
https://abcd/3.4/efgh/hijkl/mnop
然后

输出

1.1.3
2.3.4.5
3.4

说明:我将行分隔符(
RS
)指定为
/
或换行符(
\n
),然后只打印行(即换行符和/或/或换行符之间的部分)仅包含
或数字-为了达到这种效果,我使用
^
$
表示记录的开始和结束。

使用
awk
,使用GNU
awk
中显示的样本编写和测试

awk 'match($0,/([0-9]+\.){1,}[0-9]+/){print substr($0,RSTART,RLENGTH)}' Input_file
说明:添加上述内容的详细说明

awk '                               ##Starting awk program from here.
match($0,/([0-9]+\.){1,}[0-9]+/){   ##using match function to match regex of ([0-9]+\.){1,}[0-9]+ in current line. 
  print substr($0,RSTART,RLENGTH)   ##Printing sub string of matched regex above, starting index is RSTART till value of RLENGTH here.
}
' Input_file                        ##Mentioning Input_file name here.
awk '                               ##Starting awk program from here.
match($0,/([0-9]+\.){1,}[0-9]+/){   ##using match function to match regex of ([0-9]+\.){1,}[0-9]+ in current line. 
  print substr($0,RSTART,RLENGTH)   ##Printing sub string of matched regex above, starting index is RSTART till value of RLENGTH here.
}
' Input_file                        ##Mentioning Input_file name here.