AWK分配结果变量 [英] Assign AWK result to variable
问题描述
这应该是pretty straightfoward,我不知道为什么我与它挣扎。
我是从一个shell脚本中运行以下命令PSQL以查明是否所有指标均在插入数据之前被删除。
INDEXCOUNT = $(PSQL -p $ dbPort -U EnterpriseDB公司-d main_db -cSELECT COUNT(*)从all_indexes,其中index_schema ='EnterpriseDB的;)
在这一点上,INDEXCOUNT等于COUNT ------- 0
现在,如果我回应下面一行我得到我想要的结果 -
回声$ INDEXCOUNT | AWK'{打印$ 3}
我如何分配 $ INDEXCOUNT的价值| AWK'{$打印3}
来一个变量来检查它在一个IF语句?
例如:
RETURNCOUNT = $ INDEXCOUNT | AWK'{打印$ 3}
在正确猛砸以下工作:
A = $(回声111 222 33| awk的'{$打印3;}')
回声$#一个结果是33
另一种选择是将字符串转换为数组:
A =111 222 333
B =($ A) 回声$ {B [2]}#返回333
This should be pretty straightfoward and I don't know why I am struggling with it.
I am running the following psql command from within a shell script in order to find out whether all indexes have been dropped before inserting data.
INDEXCOUNT=$(psql -p $dbPort -U enterprisedb -d main_db -c "select Count(*) from all_indexes where index_schema = 'enterprisedb';")
At this point, INDEXCOUNT is equal to "COUNT ------- 0"
Now if I echo the following line I get the result I want -
echo $INDEXCOUNT | awk '{print $3}'
How do I assign the value of $INDEXCOUNT | awk ‘{print $3}’
to a variable to check it in an "IF" statement?
For example:
RETURNCOUNT=$INDEXCOUNT | awk '{print $3}'
The following works correctly on bash:
a=$(echo '111 222 33' | awk '{print $3;}' )
echo $a # result is "33"
Another option would be to convert the string to an array:
a="111 222 333"
b=($a)
echo ${b[2]} # returns 333
这篇关于AWK分配结果变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!