Skip to content

Instantly share code, notes, and snippets.

@ssg
Created March 3, 2026 21:50
Show Gist options
  • Select an option

  • Save ssg/311c061bcd4fde8350a9172b18b5bcf4 to your computer and use it in GitHub Desktop.

Select an option

Save ssg/311c061bcd4fde8350a9172b18b5bcf4 to your computer and use it in GitHub Desktop.
Some log file analysis tool I wrote back in 2003
program agg;
{$APPTYPE CONSOLE}
uses
IniFiles, SysUtils;
procedure Abort(s:string);
begin
writeln(s);
halt(1);
end;
var
F:TextFile;
s:string;
n,cnt,target,st,len,i,maxlen,a,b:integer;
sl:THashedStringList;
begin
writeln('AGG - Log file aggregator - Code by SSG Nov 2003'#13#10);
if ParamCount <> 2 then Abort('Usage: agg <filename> <column_number>');
AssignFile(F,ParamStr(1));
target := StrToIntDef(ParamStr(2),1);
Reset(F);
sl := THashedStringList.Create;
if IOResult <> 0 then Abort('Cannot open file: '+ParamStr(1));
maxlen := 0;
while not Eof(F) do begin
Readln(F,s);
cnt := 1;
st := 1;
len := 0;
for n:=1 to length(s) do begin
if s[n] = ' ' then begin
if cnt = target then begin
len := n-st;
break;
end else begin
inc(cnt);
st := n+1;
end;
end;
end;
s := copy(s,st,len);
i := sl.IndexOf(s);
if i >= 0 then begin
// already exists
sl.Objects[i] := TObject(integer(sl.Objects[i])+1);
end else begin
// new
sl.AddObject(s,TObject(1));
len := length(s);
if len > maxlen then maxlen := len;
end;
end;
CloseFile(F);
for n:=0 to sl.Count-1 do begin
for i:=n+1 to sl.Count-1 do begin
a := integer(sl.Objects[n]);
b := integer(sl.Objects[i]);
if a < b then begin
s := sl[n];
sl[n] := sl[i];
sl[i] := s;
sl.Objects[n] := TObject(b);
sl.Objects[i] := TObject(a);
end;
end;
end;
for n:=0 to sl.Count-1 do begin
writeln(sl[n]:maxlen,' ',integer(sl.Objects[n]));
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment