Bash 从sql脚本输出中提取不等于零的值
我基本上是在两个不同的数据库之间对具有相同名称的表进行行计数 我们的sql脚本如下所示:Bash 从sql脚本输出中提取不等于零的值,bash,shell,scripting,Bash,Shell,Scripting,我基本上是在两个不同的数据库之间对具有相同名称的表进行行计数 我们的sql脚本如下所示: select (select count(1) from source.abc@remotedb) - (select count(1) from target.bcd) from dual; cat result_of_sql | grep -v '^$' | paste - - - | awk -F"\t" '$3!=0{print $1}' 我们有将近2000个类似于上面的脚本 输出如下所示: s
select (select count(1) from source.abc@remotedb) - (select count(1) from target.bcd) from dual;
cat result_of_sql | grep -v '^$' | paste - - - | awk -F"\t" '$3!=0{print $1}'
我们有将近2000个类似于上面的脚本
输出如下所示:
select count(1) from source.abc@remotedb) - (select count(1) from target.abc
----------------------------------------------------------------------------
0
select count(1) from source.opo@remotedb) - (select count(1) from target.opo
----------------------------------------------------------------------------
26
select count(1) from source.asd@remotedb) - (select count(1) from target.asd
----------------------------------------------------------------------------
-95
现在,使用bash/shell脚本,我想将输出打印到一个单独的文件中,其中仅包含数值不等于0的那三行
例如:
$ cat final_result.txt
select count(1) from source.opo@remotedb) - (select count(1) from target.opo
----------------------------------------------------------------------------
26
select count(1) from source.asd@remotedb) - (select count(1) from target.asd
----------------------------------------------------------------------------
-95
-B1:匹配行前面的一行可能类似
egrep -B3 '^\-*[1-9]+$' fileinput > final_result.txt
我想这样做:
select (select count(1) from source.abc@remotedb) - (select count(1) from target.bcd) from dual;
cat result_of_sql | grep -v '^$' | paste - - - | awk -F"\t" '$3!=0{print $1}'
在哪里
去掉空行grep-v'^$'
使用制表符将每3行聚合为1行粘贴----
awk magic:打印预期结果awk-F“\t””$3=0{print$1}'