Grep在Linux中的字符串的特殊部分

Alo*_*ark 0 linux bash grep

我想要grep一部分字符串,其中包含数字和点(.).

例如:

/home/xar/11.1.0/hez
/uaa/14.0.2.5/grd/pc
Run Code Online (Sandbox Code Playgroud)

我想要的只是这一部分:

14.0.2.5
11.1.0
Run Code Online (Sandbox Code Playgroud)

我意识到cut命令不足以解决这个问题.

fed*_*qui 5

你可以使用这个grep:

$ grep -o "[0-9.]*" file
11.1.0
14.0.2.5
Run Code Online (Sandbox Code Playgroud)
  • -o 用于"仅打印匹配的部分".
  • "[0-9.]*" 匹配数字和点的任何组合.