# How to read data from file written to be human readable?

I have a file with this kind of structure: Some text a = 342 b = 222 other text c = 9834 Some text (then it repeats)

From my googling I suspect it can be done with Find[] after creating a stream from this file. But I could use some help, as I'm sure this must be a common problem with a commong solution.

• Would TextCases[string, "Number"] be helpful? Oct 8, 2016 at 0:10
• It might be. In fact, I think I can also use readlist. The advantage of this file is that the order never changes so I could setup a loop that sorts and attributes to arrays. I'll give that a shot on monday. Oct 9, 2016 at 1:43

Here's my own solution. It certainly isn't the only way to do it but it's the one I've found. Hopefully it may be of some use to others.

This solution works when you want extract numerical data from a file that is made to be human readable ("measured quantities: variable x = 0.333" etc) and it follows a pattern. So it wouldn't work for a dissertation or article, obviously. Take for example this file:

Before iteration
a = 0.2
b = 9
After Iteration
c = 34983
d = 34873847837
Before iteration
a = 33
b =...


The main idea is to use Import[filename, "Data"], then each line will be an element of this list, which you can use ToExpression[StringSplit[Data[[(appropriate index]]][[3]], where "3" would be the number after the equal sign in this case. It's just a matter to create a loop that covers the entire file saving the information you want in the arrays you want. Like this:

Data = Import[filename, "Data"],
j = 0,
b = {},
While[True,
If[(1 + j*22) + 1 > Length[Data], {Break[]}];
b = Join[b, {ToExpression[
StringSplit[Data[[(1 + j*6) + 1]]][[3]]]}];
j++],