program newlines; {$APPTYPE CONSOLE} uses SysUtils,Classes; procedure Help; begin writeln(' Program that finds new lines from file.'); writeln(' The files are sorted and then every line from new file'); writeln(' is taken and n first chracters are'); writeln(' compared agains every line in oldfile'); writeln(' and if they do not match, the line is new.'); writeln(' Only new lines are printed.'); writeln(''); writeln(' Call'); writeln(' newlines oldfile newfile [n]'); writeln(''); writeln(' Vesa Lappalainen 13.8.2005'); end; procedure Subtract(s1,s2:TStrings; n:integer); var ss1,ss2:string; i1,i2:integer; begin for i2:=0 to s2.Count-1 do begin ss2 := Copy(s2[i2],1,n); for i1:=0 to s1.Count-1 do begin ss1 := Copy(s1[i1],1,n); if ( ss1 = ss2 ) then begin s1.Delete(i1); break; end; end; end; end; var f1,f2:TStringList; i:integer; begin if ( ParamCount <= 1 ) or ( Pos('?',ParamStr(1)) > 0 ) then begin Help; Exit; end; f1 := TStringList.Create; f2 := TStringList.Create; try try f1.LoadFromFile(ParamStr(1)); f2.LoadFromFile(ParamStr(2)); f1.Sort; f2.Sort; Subtract(f2,f1,StrToIntDef(ParamStr(3),100)); for i:=0 to f2.Count-1 do begin writeln(f2[i]); end; except on e: Exception do begin writeln(e.Message); Help; end; end; finally f1.Free; f2.Free; end; end.