rm AGE/*
d=`date +%Y-%m-%d" "%T`
awk -F"^" ' $5=="RA"|| $5=="RD" {
file="AGE/"sprintf("%.4d",NR) 
print "H01"$2 >file"1"
print "H02"$8 >file"1"
print "H03"$4 >file"1"
print "H04"pomp($3) >file"1"
print "H05"$6 >file"1"
print "H06A" >file"1"
print "H07'"$d"'" >file"1"
print "H08Telemed2019 " >file"1"
print "H01"$2 >file"2"
print "H02"$8 >file"2"
print "H03"$4 >file"2"
print "H04"pomp($3) >file"2"
print "H05"$6 >file"2"
print "H06V" >file"2"
print "H07'"$d"'" >file"2"
print "H08Telemed2019 " >file"2"
print "H01"$2 >file"3"
print "H02"$8 >file"3"
print "H03"$4 >file"3"
print "H04"pomp($3) >file"3"
print "H05"$6 >file"3"
print "H06C" >file"3"
print "H07'"$d"'" >file"3"
print "H08Telemed2019 " >file"3"
}
function pomp(rt)
{
	x2=""
	x=rt
	while(substr(x,1,1)!="")
	{
		x1=substr(x,1,1)
		if(x1!="."&&x1!="-") x2=x2""x1
		x=substr(x,2)
	}
	if(length(x2)<9) x2 =0""x2
	return substr(x2,1,2)"."substr(x2,3,3)"."substr(x2,6,3)"-"substr(x2,9,1)
} '  PR1


for i in AGE/*
do
../ihd/bin/ihmu agend ../../IMP/$i -N1
done
exit

20181126^00001^17.142.186-1^0300^RA^26/12/2018^26/11/2018^26/11/2018^26/12/2018^07
20181126^00001^17.142.186-1^0319^RA^12/12/2018^26/11/2018^26/11/2018^26/12/2018^07
20181126^00001^17.142.186-1^0326^RA^19/12/2018^26/11/2018^26/11/2018^26/12/2018^07
20181126^00002^16.203.285-2^0013^RD^06/12/2018^26/11/2018^26/11/2018^26/12/2018^01
20181126^00002^16.203.285-2^0021^RD^14/12/2018^26/11/2018^26/11/2018^26/12/2018^01
20181126^00002^16.203.285-2^0027^RA^20/12/2018^26/11/2018^26/11/2018^26/12/2018^01
20181126^00002^16.621.429-7^0113^RD^06/12/2018^26/11/2018^26/11/2018^26/12/2018^01
20181126^00002^16.621.429-7^0121^RD^14/12/2018^26/11/2018^26/11/2018^26/12/2018^01
20181126^00002^16.621.429-7^0127^RA^20/12/2018^26/11/2018^26/11/2018^26/12/2018^01
20181127^00003^16.203.285-2^0010^RD^04/12/2018^27/11/2018^27/11/2018^27/12/2018^01


0000010000125/01/2019030409.085.723-129/01/2019A2019-02-24 01:22:37 Telemed2019         
0000020000125/01/2019030409.085.723-129/01/2019V2019-02-24 01:22:40 Telemed2019         
0000030000125/01/2019030409.085.723-129/01/2019C2019-02-24 01:22:43 Telemed2019         
agend=./tmp/agend
./appl/sh/agend h00"^" h01"^" h02"^" h03"^" h04"^" h05"^" h06"^" h07"^" h08 > $agend

# |  1 H00 regist 06 00   0 | 2 H01 pacien 05 51   6 | 3 H02 fechai 10 00  11 |
# |  4 H03 valida 04 00  21 | 5 H04 profes 12 52  25 | 6 H05 fechae 10 00  37 |
# |  7 H06 transs 01 00  47 | 8 H07 transc 20 00  48 | 9 H08 usuari 20 00  68 |

