-1

Given below is a script with X number of Outputs:

#!/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

Required Output:

cand1, cand2, cand3, cand62
shellter
  • 36,525
  • 7
  • 83
  • 90
Driver123
  • 133
  • 1
  • 11
  • It is not clear what you want to do. What is your question? – Yamaneko Nov 01 '12 at 18:21
  • when i try to run the above script, i get the following output as follows: cand1 cand2 cand3 cand62. But i need the output as comma separated as cand1, cand2, cand3, cand62 – Driver123 Nov 01 '12 at 18:25
  • 1
    Anyone out there ???? Please Help A.S.A.P – Driver123 Nov 01 '12 at 18:59
  • 1
    Are you ever going to solve this problem? This is at least the 3rd question related to the same query. Good luck. – shellter Nov 01 '12 at 19:01
  • 1
    Are you sure `echo $output` produces many lines of output ? – jfg956 Nov 01 '12 at 20:10
  • @shellter: Hopefully i will be solving this problem, I have to , as i have no other choice. The reason that i am facing the problem is because i will have to include this script in our product which is integrated with shell node. Thanks for the Encouraging words. – Driver123 Nov 02 '12 at 04:18
  • @jfgagne: yes ur correct. it will just give the count. – Driver123 Nov 02 '12 at 04:28
  • @jfgagne: Actually i the query should have been ....select o.candidateid from onboardingcandidates o, candidatedetails c where o.candidateid=c.candidateid and o.JOININGSTATUS='0091' and to_date(o.joiningdate)=to_date(sysdate+5); – Driver123 Nov 02 '12 at 04:29

2 Answers2

1

If you don't require spaces:

... | paste -d, -s -

If you need spaces:

... | paste -d, -s - | sed 's/,/, /g'
William Pursell
  • 204,365
  • 48
  • 270
  • 300
  • it is not helping me .... it is giving the same output ......echo $output | paste -d, -s - – Driver123 Nov 02 '12 at 05:07
  • Guys the below query worked for me ... i used listagg function ..... select listagg(o.candidateid, ',') within group (order by joiningdate, o.candidateid) from onboardingcandidates o, candidatedetails c where o.candidateid=c.candidateid and o.JOININGSTATUS='0091' and to_date(o.joiningdate)=to_date(sysdate+5); – Driver123 Nov 02 '12 at 05:30
0

Use awk and and change the ORS:

echo $output | awk -v ORS=", "  '{print $0}'
P.P
  • 117,907
  • 20
  • 175
  • 238
  • This can be simplified: `awk 1 ORS=", "` – William Pursell Nov 01 '12 at 19:10
  • Guys the below query worked for me ... i used listagg function ..... select listagg(o.candidateid, ',') within group (order by joiningdate, o.candidateid) from onboardingcandidates o, candidatedetails c where o.candidateid=c.candidateid and o.JOININGSTATUS='0091' and to_date(o.joiningdate)=to_date(sysdate+5); – Driver123 Nov 02 '12 at 05:29