2012-11-01 2 views
-1

의 값의 N 번호에 대한 쉼표로 분리 된 출력을 출력의 X 번호가있는 스크립트입니다 필요 :은 아래 쉘

#!/bin/bash 

instant_client="/root/ora_client/instantclient_11_2" 
output=`$instant_client/sqlplus -s HRUSER/[email protected] <<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 

필수 출력 :

cand1, cand2, cand3, cand62 
+0

당신이 무엇을 원하는 분명하지 않다. 귀하의 질문은 무엇인가? – Yamaneko

+0

위의 스크립트를 실행하려고하면 다음 출력이 표시됩니다. cand1 cand2 cand3 cand62. 하지만 출력을 쉼표로 분리해야 cand1, cand2, cand3, cand62로 바꿔야합니다. – Venkatesh

+1

아무도 없습니까? 제발 도와주세요 A.S.A.P – Venkatesh

답변

1

공백이 필요하지 않은 경우 :

... | paste -d, -s - 

당신이 필요로하는 경우 공간 :

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

그것은 나에게 도움이되지 않는다. ... 그것은 같은 결과를 낸다 ...... echo $ output | 붙여 넣기 -d, -s- – Venkatesh

+0

남자들이 나를 위해 일한 쿼리는 ... 나는 listagg 함수를 사용했다. ..... 그룹 내에서 listagg (o.candidateid, ',')를 선택했다. (from joindate, o.candidateid) onboardingcandidates o, candidatedetails c 여기서 o.candidid = c.candidate 및 o.JOININGSTATUS = '0091'및 to_date (o.joiningdate) = to_date (sysdate + 5); – Venkatesh

0

사용 AWK와와는 ORS을 변경

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

이것은 간단해질 수 있습니다 :'awk 1 ORS = "," –

+0

아래 질문은 나를 위해 일했습니다 ... 나는 listagg 함수를 사용했습니다 ..... select listagg (o.candidate, ',') group (order ocandidate = ccandidate 및 o.JOININGSTATUS = '0091'및 to_date (o.joiningdate) = to_date (sysdate + 5); – Venkatesh