Does anyone know how to use VBA code to deal with Unix terminators that come across in ascii files transferred from Unix to PC? I cannot get my code to correctly read individual lines of data in files of this type.
Due to the Unix termination characters that come across from our Unix server, extremely long lines (>1000 characters) gets read into LineString. My program cannot then read the appropriate keywords to know when to start reading data. If the data file is loaded into a text editor and saved, the problem is solved - somehow doing that gets rid of the Unix terminators.
Your mention of dos2unix fired some synapses in a dark corner of my severly atrophied brain and I remembered that there is also a unix2dos command on dos. That command can be invoked from within my VBA code via the Shell command and has solved the problem. Many thanks,
DOS (Windows) and Unix have different line terminators. MS uses CRLF, Unix uses LF only. Which is why Windows thinks you have really long lines in your file with strange characters where the linefeeds should be. unix2dos is a venerable and pretty much bulletproof utility to handle this, so your solution sounds solid. If you can check the return code from the shell call, it will make your program more robust...
Steve
[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object:erlDesignPatterns)[/small]
The use of the unix2dos command not only allows me to read the file, it also corrects the file so that it can then be sent to and viewed by clients in their various software. Thanks to everyone for your help.
Another elegant technical solution dashed on the rocks of incomplete requirements specification...
Steve
[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object:erlDesignPatterns)[/small]
I was operating under the mistaken impression that unix2dos is part of a standard Windows installation, which it is not. So I have tried the FileSystemObject route and that does read the file in correctly. Can it also correct the file (from unix terminators to dos terminators) on the fly as unix2dos does or do I have to write out each line to a new file and then rename it?
unix2dos reads the file, writes out a temporary, deletes the original, and renames the temporary back to the original name. So it doesn't really 'do it on the fly' as you suggest, and you will have to do what it does I'm afraid...
Steve
[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object:erlDesignPatterns)[/small]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.