Text processing/2: Difference between revisions
Content added Content deleted
('find' -> 'fully') |
(Added zkl) |
||
Line 2,407: | Line 2,407: | ||
Invalid data records: 454 |
Invalid data records: 454 |
||
Total records: 5471</lang> |
Total records: 5471</lang> |
||
=={{header|zkl}}== |
|||
<lang zkl> // the RegExp engine has a low limit on groups so |
|||
// I can't use it to select all fields, only verify them |
|||
re:=RegExp(0'|^(\d+-\d+-\d+)| + 0'|\s+\d+\.\d+\s+-*\d+| * 24 + ".+$"); |
|||
w:=Utils.Helpers.zipW(File("readings.txt"),[1..]); //-->lazy (line,line #) |
|||
reg datep,N, good=0, dd=0; |
|||
foreach line,n in (w){ |
|||
N=n; // since n is local to this scope |
|||
if (not re.search(line)){ println("Line %d: malformed".fmt(n)); continue; } |
|||
date:=line[re.matchedNs[1].xplode()]; // I can group the date field |
|||
if (datep==date){ dd+=1; println("Line %4d: dup date: %s".fmt(n,date)); } |
|||
datep=date; |
|||
if (line.replace("\t"," ").split(" ").filter()[1,*] // blow fields apart, drop date |
|||
.pump(Void,T.fp(Void.Read,1), // get (reading,status) |
|||
fcn(_,s){ // stop on first problem status and return True |
|||
if(s.strip().toInt()<1) T(Void.Stop,True) else False |
|||
})) continue; |
|||
good+=1; |
|||
} |
|||
println("%d records read, %d duplicate dates, %d valid".fmt(N,dd,good));</lang> |
|||
{{out}} |
|||
<pre> |
|||
Line 85: dup date: 1990-03-25 |
|||
Line 456: dup date: 1991-03-31 |
|||
Line 820: dup date: 1992-03-29 |
|||
Line 1184: dup date: 1993-03-28 |
|||
Line 1911: dup date: 1995-03-26 |
|||
5471 records read, 5 duplicate dates, 5017 valid |
|||
</pre> |
|||
{{omit from|GUISS}} |
{{omit from|GUISS}} |