How many commas

From: Tony Austin <taustin_at_solucient.com>
Date: Tue, 11 Sep 2001 10:33:07 -0700

 
I have a text file that looks like
 
hospital_id, R0,R5,R15,R9
1010,Y,Y,Y,Y
1020,N,N,Y,N
1030,Y,N,N,Y
 
I would like to take the first line, hospital_id... and turn it into :
 
hospital_id number, R0 varchar, R5 varchar, etc.
 
The problem is that there will be varying number of columns each time. So
after I grep out the line with hospital in it, how can I determine how many
commas are in the line so that I can loop through it and perform something
like this:
 
 
file="test.txt"
C=`grep -i hosp_id $file`
echo $C
C1=`echo $C | cut -d',' -f1`
echo $C1
C2=`echo $C | cut -d',' -f2`
echo $C2
C3=`echo $C | cut -d',' -f3`
echo $C3
 
> test.sh
HOSP_ID,RO,RS
HOSP_ID
RO
R5
 
Thanks. Tony
R15
Received on Tue Sep 11 2001 - 17:34:19 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:42 NZDT