Question:
Fast/Easy way to parse text files?
2011-06-23 18:04:00 UTC
Hi,

I'm working on some research and I tend to generate a lot of data files that have to be individually analyzed. I'm looking into making this task easier by organizing my data output in certain ways.

The file I generate has 3 columns of numbers. I want to delete the second column but keep some of the information and store that information in a separate text file or other output.

Additionally, the file contains data from up to 20 experiments all listed in the same 3 columns. I'd like to separate this data and output each experiment into a separate text file.

I have a pretty limited software background (java class and algorithms), so it would help me out immensely if anyone could point out the simplest way to make this happen using any methods you can think of.

Huge thanks for any input
Three answers:
misaltas
2011-06-23 18:14:29 UTC
I would just knock this out in VB. I'd create a program that is going to be runnable on any text file of similar format. It would probably take a dozen or two lines of code at the most.



The System.IO namespace has classes called StreamReader, StreamWriter that can be used to open/read, create/write text files. System.IO File class has CreateText and OpenText methods for handling the file itself. The Stream~ classes have ReadLine and WriteLine methods that deal with each line of text as a String. For each line of text you will be reading and writing, VB includes several string manipulation functions for parsing and constructing strings and parts of the line, down to the character, delimiter, etc., in whatever format you have or might want.



If you don't own a copy of Visual Studio, you can do this with Visual Basic Express which is downloadable from Microsoft for free.
Yahgoogle
2011-06-23 19:29:35 UTC
You can try Replace Pioneer, it's an windows application, which is easy to handle your problems, and no programming is needed, you can make the operation first time and save the auto-generated script for re-use next time.



For extracting specified columns, you can check following link:



How to extract column 3,6,7,8 from each line of text?

http://www.mind-pioneer.com/services/691_Text_file_parser.html



For splitting a file into different files containing different experiments, please check following link:



How to split a csv file according to the value of column A?

http://www.mind-pioneer.com/services/789_Text_file_splitter.html



You can also search "column csv" at following link for many comprehensive examples, or raise your own questions on the same website for technical support.



http://www.mind-pioneer.com/services/conv_search.php?key=column+csv&type=all
campblin
2016-11-12 00:52:33 UTC
do no longer use a streamreader and array. hook up with the text textile record using OLEDB by ability of treating the textfile as a table and cargo the textfile right into a datatable, then you certainly can purely precise an sq. assertion or LINQ assertion to delete the Rows that have Randomword.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...