Converting Column values to comma delimted single Row

I have a requirement in which i have to read a file which has multiple columns seperated by a pipe "|" from this i have to read each column values seperately and create a comma seperated row for the column and write to another file.

eg:

Input file:
ColA ColB
1 2
2 x
3 y
4 c
5 q

from this i have to create two filles, each having data as

file_colA:
1,2,3,4,5

file_colB:
2,x,y,c,q

i have created shell script using a for loop, which may take long time when i implement it in prod.

can any one suggest an approach using awk or sed?

thanks

file=/path/to/inputfile
numcols=2 ## adjust to taste
n=1
  IFS='
'
while [ $n -le $numcols ]
do
  {
    printf "%s," $( cut -d '|' -f "$n" "$file" )
    echo
  } > file_col$n
  n=$(( $n + 1 ))
done

it doesn't look like your 'input' file has '|' separated fields.
does the 'ColA' and 'ColB' headers actually exist in the 'input' file?

sorry for the wrong file
Input file:
ColA ColB
1|2
2|x
3|y
4|c
5|q

and it doesnt have column header.

thanks johnson for the approach, but it will try to read the file line by line, which i want to avoid. since in production i may have millions of records and this may cause a bottleneck.

how else would you transpose a matrix?

i have single column which is starting with same string(many number of rows)
i have to convert each into a single row.how can i do that?

laknar
std
mes
23
55
laknar
isd
phone no
address
amount
99

I have to convert above like below.

laknar|std|mes|23|55
laknar|isd|phone no|address|amount|99