只需要从输出中获取值

Need to get only the value from the output

当我通过 shell 脚本执行数据库查询时,我得到以下输出

SQL*Plus: Release 10.2.0.5.0 - Production on Thu Jun 22 02:50:47 2017

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Release 10.2.0.5.0 - 64bit Production

SQL> 
SUM(SUM(CURRENTCOUNT))
----------------------
           1182870

SQL> Disconnected from Oracle Database 10g Release 10.2.0.5.0 - 64bit Production

我需要用sed去掉里面的其他内容,只得到1182870 我用了

sed -n '/COUNT(\*)/{n;n;p}'

要在 sqlplus 报告中禁止显示列标题,请输入:

SET HEADING OFF

https://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12040.htm#i2699001

您的命令稍有改动。

<sql-command>|sed -n '/CURRENTCOUNT/{n;n;p}'
           1182870

the-sql-command | grep -A 2 '^SUM(SUM' | tail -n 1 | grep -o '[0-9]*'