【发布时间】:2012-05-23 13:09:52
【问题描述】:
我需要从文件中获取特定的版本字符串(称为 version.lst)并用它来比较 shell 脚本中的另一个。例如,该文件包含如下所示的行:
V1.000 -- build date and other info here -- APP1
V1.000 -- build date and other info here -- APP2
V1.500 -- build date and other info here -- APP3
.. 等等。假设我正在尝试从 APP1 获取第一个版本(在本例中为 V1.000)。显然,版本可以更改,我希望这是动态的。我现在所拥有的工作:
var = `cat version.lst | grep " -- APP1" | grep -Eo V[0-9].[0-9]{3}`
到 grep 的管道将获取包含 APP1 的行,而到 grep 的第二个管道将获取版本字符串。但是,我听说 grep 不是这样做的方法,所以我想学习使用 awk 或 sed 的最佳方法。有任何想法吗?我对两者都是新手,还没有找到足够简单的教程来学习它的语法。他们支持 egrep 吗?谢谢!
【问题讨论】: