Thanks to all; here's what looks to be best solution

• To: mathgroup at smc.vnet.net
• Subject: [mg36677] Thanks to all; here's what looks to be best solution
• From: "1.156" <rob at piovere.com>
• Date: Wed, 18 Sep 2002 02:10:18 -0400 (EDT)
• References: <alrtp5\$hc2\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Thanks to all who helped me on this. Tomas in Mexico appears to have nailed
this thing.  Here is what I'm using now:

In[1]:=
a=ReadList["197-tst.txt",Word,RecordLists->True,
WordSeparators->None];

In[2]:=
flds={{25,31}, {32,39},{40,46},{47,54},{55,62},{63,70},{71,78},{79,86},{87,
94},{95,102},{103,110}};

Define this function:

In[3]:=
f[x_]:=ToExpression[StringTake[x[[1]],#]]&/@flds

Now, map this function onto a:

In[8]:=
f/@a
Out[8]=
{{5935.8,5946.66,27.06,-1281.9,-229.,321.,317.,367.,-115.,126.,146.},{5935.8
....
************
The data is now in a matrix of numbers and each variable is in a column.
Now I just transpose this to get each variable in a row for easy access (apparently
Mathematica has no way to directly access a column in a matrix, you gotta transpose I think)

Rob

"1.156" wrote:

> I've got to extract some numbers from a file that are in lines of text. Since the line contents are not numbers, I presume I must pull the line out as a string.  Here I start by pulling out just one line:
>
> inFile = OpenRead["197-tst.txt"]
> y = ReadList[inFile, String, 1, RecordLists -> True]
> Close[inFile];
>
> This appears to pull in a line. Now I want to take characters 25 to 110 to get just the stuff I want:
> y1=StringTake[y ,{25,110}];
>
> Here's the output.  StringTake doesn't seem to work.
>
> StringTake[{aEX-004   2002197 0 0 0 5935.80 5946.66  27.06 -1281.9   -229.    321.    317.    367.   -115.    126.    146.   -410.  -426.000000EF   75.}, {25, 110}]
>
> It doesn't take loading another package as far
> as I can tell from the help.  I'm thinking that it doesn't work because it's trying to work on a list
> rather than a string. I've tried Flatten, and other stuff to try to get to just a string and not a list but
> nothing has worked so far.  I'm a long way from getting to those numbers in there but heck, I
> can't even get to the string.  Can anyone point me in the right direction?
>
> Thanks, Rob

```

• Prev by Date: JLink and speeding up graphics display by java routine
• Next by Date: Re: LaTeX and Mathematica
• Previous by thread: Re: JLink and speeding up graphics display by java routine
• Next by thread: RE: RE: Re: Why is my Implementation of Sorted Trees So Slow?