Solved

VBA: Read textfiles in Unix format

Posted on 2006-06-23
6
1,390 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Window placement 17 64
Excel object stays open 19 65
Sending a email via excel using vba 6 56
Protecting vb6 & .Net code Obfuscation 18 49
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now