Board index » delphi » Convert text file from DOS to Unix type

Convert text file from DOS to Unix type

Can someone give me (or point me to) an example of converting
all CR/LF (#13 #10) pairs in a text file to just CR (#13)?

I am creating a perl cgi script by writing to a text file with the
normal text I/O routines, but it will always append a CR/LF
to the end of the line. I need to either change all of those
to just CR after it is created, or during creation because with
the CR/LF pairs, the .cgi file is not executed correctly.

Someone please help.

Thank You,

Bryan Mohr
-------------------------------------------------------
Bryan Mohr (br...@herp.com)
http://www.herp.com
-------------------------------------------------------

 

Re:Convert text file from DOS to Unix type


Just wanted to point out that Unix usually requires a LF (not a CR) to
end lines.

SPL

---------------------------

Bryan Mohr a crit:

Quote

> Can someone give me (or point me to) an example of converting
> all CR/LF (#13 #10) pairs in a text file to just CR (#13)?

> I am creating a perl cgi script by writing to a text file with the
> normal text I/O routines, but it will always append a CR/LF
> to the end of the line. I need to either change all of those
> to just CR after it is created, or during creation because with
> the CR/LF pairs, the .cgi file is not executed correctly.

> Someone please help.

> Thank You,

> Bryan Mohr
> -------------------------------------------------------
> Bryan Mohr (br...@herp.com)
> http://www.herp.com
> -------------------------------------------------------

Re:Convert text file from DOS to Unix type


Procedure DOSToUNIX(Filename : String):
Var
  File : TStingList;
  I : Byte;
  X : Byte;
begin
  File := TStringList.Create;
  File.LoadFromFile(Filename);
  For I := 0 to File.Count - 1  do
  begin
    While Pos(#13#10, File[I]) <> 0 do
    begin
      X := File[I][Pos(#13#10, File[I])];
      File[I][X] := #13;
      File[I][X] := '';
    end;
  end;
  File.Free;
end;

Perhaps this work. Haven't tried it...................

--
Sten Karsten Vartdal
stenvart-remo...@online.no
http://home.sol.no/~stenvart/

Other Threads