Text processing/2: Difference between revisions
Content added Content deleted
(→{{header|Kotlin}}: Re-ran program following recovery and mirroring of full data file.) |
|||
Line 107: | Line 107: | ||
text s; |
text s; |
||
if ( |
if (~l != 49) { |
||
error("wrong number of fields"); |
error("wrong number of fields"); |
||
} |
} |
||
s = |
s = l[0]; |
||
if ( |
if (~s != 10 || s[4] != '-' || s[7] != '-') { |
||
error("bad date format"); |
error("bad date format"); |
||
} |
} |
||
atoi(delete(delete(s, 7), 4)); |
l[0] = atoi(delete(delete(s, 7), 4)); |
||
i = 1; |
i = 1; |
||
while (i < 49) { |
while (i < 49) { |
||
l[i] = atof(l[i]); |
|||
i += 1; |
i += 1; |
||
l[i] = atoi(l[i]); |
|||
i += 1; |
i += 1; |
||
} |
} |
||
Line 129: | Line 129: | ||
main(void) |
main(void) |
||
{ |
{ |
||
integer goods; |
integer goods, i, v; |
||
file f; |
file f; |
||
list l; |
list l; |
||
index x; |
|||
goods = 0; |
goods = 0; |
||
f.affix("readings.txt"); |
|||
while |
while (f.list(l, 0) != -1) { |
||
if (!trap(check_format, l)) { |
if (!trap(check_format, l)) { |
||
if ( |
if (x.key(v = lf_pick(l))) { |
||
v_form("duplicate ~ line\n", |
v_form("duplicate ~ line\n", v); |
||
} |
} |
||
⚫ | |||
x[v] = 0; |
|||
i = 1; |
|||
while (i < 48) { |
|||
if (l[i] < 1) { |
|||
break; |
|||
⚫ | |||
⚫ | |||
⚫ | |||
if (49 < i) { |
|||
goods += 1; |
|||
} |
} |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
} |
||
} |
} |
||
} |
} |
||
o_(goods, " good lines\n"); |
|||
o_text(" good unique lines\n"); |
|||
return 0; |
return 0; |
||
}</lang> |
}</lang> |
||
{{out}} (the "reading.txt" needs to be converted to UNIX end-of-line) |
{{out}} (the "reading.txt" needs to be converted to UNIX end-of-line) |
||
<pre>duplicate |
<pre>duplicate 19900325 line |
||
duplicate |
duplicate 19910331 line |
||
duplicate |
duplicate 19920329 line |
||
duplicate |
duplicate 19930328 line |
||
duplicate |
duplicate 19950326 line |
||
5017 good lines</pre> |
|||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |