Bash 使用grep查找版本号

Bash 使用grep查找版本号,bash,macos,grep,Bash,Macos,Grep,基本上,我正在为osx上的emesene创建一个更新检查器。我需要从这个文件中找出版本号: 版本号位于文件中的self.version='version',例如self.version='1.6.3' 然后需要将版本号保存在文件中 这是否可以使用grep?如果可以使用sed(1),则可以使用单个命令提取它: grep "self.VERSION = '.*'" Controller.py | cut -d "'" -f 2 > file sed -n "s/.*self\.VERSION

基本上,我正在为osx上的emesene创建一个更新检查器。我需要从这个文件中找出版本号:

版本号位于文件中的self.version='version',例如self.version='1.6.3'

然后需要将版本号保存在文件中

这是否可以使用grep?

如果可以使用
sed(1)
,则可以使用单个命令提取它:

grep "self.VERSION = '.*'" Controller.py | cut -d "'" -f 2 > file
sed -n "s/.*self\.VERSION = '\([^']*\)'.*/\1/p" Controller.py > file
如果可以使用
sed(1)
,则可以使用单个命令将其提取:

sed -n "s/.*self\.VERSION = '\([^']*\)'.*/\1/p" Controller.py > file
你可以用awk

$ awk -F"['-]" '/VERSION[ \t]=/{print $2}' Controller.py
1.6.3
你可以用awk

$ awk -F"['-]" '/VERSION[ \t]=/{print $2}' Controller.py
1.6.3