Organizing Messy Notepad data
1 view (last 30 days)
Show older comments
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!!
0 Comments
Answers (2)
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.
1 Comment
Walter Roberson
on 28 Feb 2015
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.
0 Comments
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!