Link to home
Start Free TrialLog in
Avatar of IgnaceLamine
IgnaceLamine

asked on

VBA: Read textfiles in Unix format

I have a huge textfile in Unix format of several megabytes that I want to read line by line. How do I do this in VBA?
Do I have to convert it to DOS/Windows format first? How?
Avatar of [ fanpages ]
[ fanpages ]

Hi,

The UNIX and DOS (and Windows) operating systems differ in the format in which they store text files.

DOS places both a carriage return character [vbCr or Chr$(13)] & a line feed character [vbLf or Chr$(10)] at the end of each line of a text file, but Unix uses only a line feed character.

Some DOS applications need to see carriage return characters at the ends of lines, and may treat Unix-format files as giant single lines.

Some Unix applications won't recognize the carriage returns added by DOS, and will display Ctrl-M characters at the end of each line (shown on-screen as ^M).


You do not have to convert UNIX text files to DOS format in order to read them, but you need to ensure that whilst reading the lines with VBA that you then replace all single vbLf characters with vbCrLf.

BFN,

fp.
ASKER CERTIFIED SOLUTION
Avatar of [ fanpages ]
[ fanpages ]

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks (again) Dan.