Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell中N个值需要逗号分隔的输出_Shell_Unix_Scripting_Scripting Language - Fatal编程技术网

Shell中N个值需要逗号分隔的输出

Shell中N个值需要逗号分隔的输出,shell,unix,scripting,scripting-language,Shell,Unix,Scripting,Scripting Language,下面给出了一个具有X个输出的脚本: #!/bin/bash instant_client="/root/ora_client/instantclient_11_2" output=`$instant_client/sqlplus -s HRUSER/HRUSER@TOMLWF <<EOF set heading off set feedback off set lines 10000 set pagesize 10000 select count (1) from onboardi

下面给出了一个具有X个输出的脚本:

#!/bin/bash

instant_client="/root/ora_client/instantclient_11_2"
output=`$instant_client/sqlplus -s HRUSER/HRUSER@TOMLWF <<EOF
set heading off
set feedback off
set lines 10000
set pagesize 10000
select count (1) from onboardingcandidates o, candidatedetails c where o.candidateid=c.candidateid and     o.JOININGSTATUS='0091' and to_date(o.joiningdate)=to_date(sysdate+5);

EOF

exit`

echo $output

Output:
cand1
cand2
cand3
cand62

如果不需要空格,请执行以下操作:

... | paste -d, -s -
如果您需要空间:

... | paste -d, -s - | sed 's/,/, /g'

使用awk并更改ORS:

echo $output | awk -v ORS=", "  '{print $0}'

你想做什么还不清楚。您的问题是什么?当我尝试运行上述脚本时,我得到如下输出:cand1 cand2 cand3 cand62。但我需要以逗号分隔的输出,如cand1,cand2,cand3,cand62有人吗????请帮助A.S.A.你解决过这个问题吗?这至少是与同一查询相关的第三个问题。祝你好运。你确定
echo$output
会产生很多行输出吗?这可以简化:
awk 1 ORS=“,”
伙计们,下面的查询对我有用。。。我使用了Listag函数。。。。。从Onboarding候选者o,CandidatedDetails c中选择组内的Listag(o.candidateid,,'),其中o.candidateid=c.candidateid,o.JOININGSTATUS='0091',to_date(o.joiningdate)=to_date(sysdate+5);这对我没有帮助。。。。它给出了相同的输出……echo$output | paste-d,-s-Guys下面的查询对我有用。。。我使用了Listag函数。。。。。从Onboarding候选者o,CandidatedDetails c中选择组内的Listag(o.candidateid,,'),其中o.candidateid=c.candidateid,o.JOININGSTATUS='0091',to_date(o.joiningdate)=to_date(sysdate+5);
echo $output | awk -v ORS=", "  '{print $0}'