如何解析输出并将其存储到变量中

时间:2014-09-02 11:13:56

标签: linux shell parsing

如何从以下命令获取值8.4.1并使用shell脚本将其存储到变量中。

   [root@testserver bin]# ./psql --version

   **psql (PostgreSQL) 8.4.1**

   contains support for command-line editing

   [root@testserver bin]#

提前致谢。

1 个答案:

答案 0 :(得分:2)

LINE=`psql --version | grep -oE "[0-9\.]+"` && echo $LINE

grep - print lines matching a pattern
-E - using regex
-o - showing only matching result, not a whole line
[0-9\.]+ - regex, which find a string with numbers and dots
相关问题