Text processing/2: Difference between revisions

(→‎{{header|Kotlin}}: Re-ran program following recovery and mirroring of full data file.)
Line 107:
text s;
 
if (l_length(~l) != 49) {
error("wrong number of fields");
}
 
s = lf_q_text(l)[0];
if (length(~s) != 10 || s[4] != '-' || s[7] != '-') {
error("bad date format");
}
l[0] = atoi(delete(delete(s, 7), 4));
 
i = 1;
while (i < 49) {
l_r_real(l, [i,] = atof(l_q_text(l, [i))]);
i += 1;
l_r_integer(l, [i,] = atoi(l_q_text(l, [i))]);
i += 1;
}
Line 129:
main(void)
{
integer goods, i, v;
file f;
list l;
recordindex rx;
 
goods = 0;
 
f_affix(f, .affix("readings.txt");
 
while (f_list(f, .list(l, 0) != -1) {
if (!trap(check_format, l)) {
if (r_keyx.key(r,v l_head= lf_pick(l))) {
v_form("duplicate ~ line\n", l_head(l)v);
} else {
integer i;
 
x[v] r_put(r, l_head(l),= 0);
i = 21;
while (i < 4948) {
if (l_q_integer(l, [i)] !=< 1) {
break;
}
i += 2;
}
if (49 < i) {
goods += 1;
}
i += }2;
}
if (48 < i) += 2;{
integergoods i+= 1;
}
}
}
 
o_integero_(goods, " good lines\n");
o_text(" good unique lines\n");
 
return 0;
}</lang>
{{out}} (the "reading.txt" needs to be converted to UNIX end-of-line)
<pre>duplicate 1990-03-2519900325 line
duplicate 1991-03-3119910331 line
duplicate 1992-03-2919920329 line
duplicate 1993-03-2819930328 line
duplicate 1995-03-2619950326 line
50135017 good unique lines</pre>
 
=={{header|AutoHotkey}}==
Anonymous user