From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <102653680321915.tru64-unix-managers.marc@archive.invalid> From: Tony Austin Date: Tue, 11 Sep 2001 17:33:07 +0000 To: tru64-unix-managers Subject: How many commas X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=102653680321915 MIME-Version: 1 Content-Type: multipart/mixed; boundary="------_=_NextPart_001_01C13AE7.D1B59800" This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C13AE7.D1B59800 Content-Type: text/plain; charset="iso-8859-1" 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 ------_=_NextPart_001_01C13AE7.D1B59800 Content-Type: text/html; charset="iso-8859-1"
 
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
------_=_NextPart_001_01C13AE7.D1B59800--