我想从grep / sed中获取此列表:
some-text_of-1.6.6-11
text_r6.5.5-text1.6.6-11
text_r6.5.5-something6.6.6-11
text_r6.5.5-yess-2.6.6-11
只有最后的数字,所以:
1.6.6-11
6.6.6-11
2.6.6-11
在1.6.6-11,2.6.6-11,6.6.6-11之前可能有任何(任何角色),但之后没有任何内容。
感谢您的回答。
答案 0 :(得分:1)
使用sed和sort。
$ sed 's/.*[^0-9]\([0-9]\+\.[0-9]\+\.[0-9]\+-[0-9]\+\)$/\1/g' file | sort -u
1.6.6-11
2.6.6-11
6.6.6-11
答案 1 :(得分:0)
grep -o [0-9][0-9.-]*$ file
<强>解释强>
[0-9] # Match a digit
[0-9.-]* # Match digits, dots or dashes
$ # Anchor the search to the end of the string
-o
选项告诉grep
仅输出行的匹配部分而不是整行。
答案 2 :(得分:0)
sed 'H;s/.*//;x
:cycle
s/\(.*\)\([-0-9.]\{1,\}\)$/\2\1/
t cycle
s/\n.*//;s/^[-.]*//' YourFile
更通用于任何长度的数字和点,减去
答案 3 :(得分:0)
一种可能性是grep或egrep,将输出限制为与-o:
的匹配egrep -o "[0-9]\.[0-9]\.[0-9]-[0-9]+" inputfile
或者使用sed:
sed 's/.*\([0-9]\.[0-9]\.[0-9]\-[0-9]\+\)$/\1/' inputfile
答案 4 :(得分:0)
这是一个awk
awk -F"[-.a-z]" '{print $(NF-3)"."$(NF-2)"."$(NF-1)"-"$NF}' file
1.6.6-11
1.6.6-11
6.6.6-11
2.6.6-11
通过将字段分隔符设置为-
,.
或a-z
,我们会获得最后4
个字段。