Unix to DOS Text file conversion

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
giovanniroi
Junior Coder
Posts: 21
Joined: Fri Jul 03, 2009 4:36 pm
Location: Milan,Italy

Unix to DOS Text file conversion

Post by giovanniroi » Wed Feb 09, 2011 2:38 pm

Dear Support,
I need to convert a Unix text file that have big size ( 180 MB ) to Dos Text File. To the end of the conversion process I need to make a LOG Text file with a simple text "END File conversion"

I Try this code:

ReadFile>C:\Path\filetoread.txt,data
StringReplace>data,"LF",%CRLF%,data

but I have a message "out of memory"

Can You help me?

Thank'for teh support

Giovanni Roi

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Wed Feb 09, 2011 5:29 pm

This code has not been tested, but it should get you
on the right track. Since it processes one line at a time
instead of the whole file in memory, this should work for
you on very large files.

Code: Select all

 //Change this to 0 if this does not suit your needs
 Let>WLN_NOCRLF=1


 Let>k=1
Label>start
 ReadLn>c:\temp\test.txt,k,line
 If>line=##EOF##,finish
 StringReplace>line,%LF%,%CRLF%,line
 WriteLn>c:\temp\test2.txt,result,line
 If>result<>0,Error
 Let>k=k+1
 Goto>start
Label>Error
  MessageModal>An error occured. Error number is %result%
Label>finish


giovanniroi
Junior Coder
Posts: 21
Joined: Fri Jul 03, 2009 4:36 pm
Location: Milan,Italy

Code don't work

Post by giovanniroi » Fri Feb 11, 2011 10:19 pm

Thank' for the suggestion,
I Try to use the code but the result is a file where any line lose the format ( my file is a fixed format record).

I think that for this problem I need a code that manage all the file in one step.

I find this Visual Basic code that solve this problem but I am not available to make a VB code.

I need a macro scheduler code that work in the same way.

Can You help me?

Thank's

Best regards

Giovanni Roi

=====VB code that solve the problem===
l = FileLen(NomeFile)
fl = FreeFile

Open NomeFile For Binary As fl
Buf = Space(l)
Get fl, , Buf
Close fl
Buf = Replace(Buf, Chr(10), vbCrLf)

Open Trim(Token(1)) For Binary As fl
Put fl, , Buf
Close fl
============================

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Sat Feb 12, 2011 9:01 am

//Change this to 0 if this does not suit your needs
Let>WLN_NOCRLF=1

Did you not notice the comments at the top?


When I had time to actually run the sample code
simply changing the variable at the top from 1 to 0
made it work perfectly for me. A file with only LF (line feed)
characters as used by Unix/Linux was transformed into
a file with CRLF (Carriage Return Line Feed) characters
as used by DOS and Windows.

giovanniroi
Junior Coder
Posts: 21
Joined: Fri Jul 03, 2009 4:36 pm
Location: Milan,Italy

The code work

Post by giovanniroi » Sat Feb 12, 2011 9:27 am

I change the parameter to 0 and the code work well.
There is only a little question. The convertion line to line is very slow and need many time to convert my file of 90MB.

Is not possible to manage more record in the same time?

Than'ks for the support

Regards

Giovanni Roi

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Sat Feb 12, 2011 1:35 pm

but I have a message "out of memory"
At least you are able to finish now (line by line) and not run out of memory!


There may be some special purpose utilities coded in C or assembly language which would be faster - you could do a google search for those.
Here is one example
http://www.wischik.com/lu/programmer/crlf.html

You could try coding the routine in VBScript using RegX (regular expressions) to do the pattern replacement, then calling the routine from Macro Scheduler using VBEval>

One other thought -- You could setup a FTP server on a Windows machine, and doing an ASCII type transfer will also convert the LF to CRLF as part of the transfer process. Since FTP has been around a long time, this process is pretty well optimized and should be fast.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts