Solved

VBA: Read textfiles in Unix format

Posted on 2006-06-23
6
1,469 Views
Last Modified: 2012-05-05
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?
0
Comment
Question by:IgnaceLamine
  • 3
6 Comments
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 16967515
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.
0
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 125 total points
ID: 16967530
As example of VBA to read UNIX text files can be found here:

"Replace line-feeds with carriage return / line feed"
[ http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_10444356.html ]

There is also reference to a utility you can use instead called "unix2dos".

The link in the PAQ is now offline, but searching in Google can return many similar tools, such as:
[ http://www.nichesoftware.co.nz/unix2dos.html ]


BFN,

fp.


0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 17309948
Thanks (again) Dan.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question