Organizing Messy Notepad data

7 views (last 30 days)
Matlabbey
Matlabbey on 23 Jul 2012
Commented: Walter Roberson on 28 Feb 2015
I have some data in Notepad that is a mess. It's a .txt file.There is basically no space between any of the different columns which hold different data. I know the spaces for the data. For example, Columns 1-2 are X, Columns 7-10 are Y....
How can I organize this? Can it be done in R? What is the best way to do this?
Thanks!!

Answers (2)

Jason Ross
Jason Ross on 23 Jul 2012
Edited: Jason Ross on 23 Jul 2012
I would do it in a regular expression. Take a look at the "Positional" and "Lookaround" operators:
You should be able to get the first columns and second columns this way without a problem.
You can do this in whatever language you want, as long as it supports regular expressions -- M, Perl, shell (sed/awk), etc. The actual syntax will vary depending on which on you pick.
You could also do this without regular expressions, counting character places, but you might need to do some transformations of the data type.
The "best" way is the one that works with whatever you are doing with the data next. Ideally, the output will be in a format that is readily useful to the next processing step.

Albert Yam
Albert Yam on 23 Jul 2012
Edited: Albert Yam on 23 Jul 2012
For general cases, Jason's response is probably the way to go.
But if the information is delimited, you can try http://www.mathworks.com/help/techdoc/ref/dlmread.html.
Edit. Actually, if you know the columns, and they are consistent. You can load into EXCEL and "Text to Columns" with fixed width. Then load that into Matlab.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!