Retrieve a Text File by Column
【Question】
Java Read Text Column function is similar to ReadLine().
I have a text file containing vector information by pin. It looks like this:
PHP Code:
xxxxxxxxxxxxxxxxxxxx
pppppppppppppppppppp
iiiiiiiiiiiiiiiiiiii
nnnnnnnnnnnnnnnnnnnn
12345689111111111122
012345678901
Count PatAdr
(Main) (Main)
1 0 1000000000000010XXXX
2 0 1000000000000010XXXX
3 0 1000000000000010XXXX
4 0 1000000000000010XXXX
5 0 1000000000000010XXXX
6 0 1000000000000010XXXX
7 0 1000000000000010XXXX
8 0 1000000000000010XXXX
9 0 1000000000000010XXXX
10 0 1000000000000010XXXX
11 0 1000000000000010XXXX
12 0 1000000000000010XXXX
13 0 1000000000000010XXXX
14 0 1000000000000010XXXX
15 0 1000000000000010XXXX
16 0 1000000000000010XXXX
...
I want to extract the information column by column, and would like to be able to write or store each pin by line such as:
xpin1 11111...
xpin2 10000...
xpin3 10000...
Basically, what I am looking for is exactly the Java readLine() function described here:
http://java.sun.com/javase/6/docs/ap...redReader.html
But instead of reading a text file line-by-line, I want to read it column by column. Is there any way or function of doing this?
【Answer】
The computation involves union and rearrangement of members of a set. It’s simple to perform set-oriented operations in Java though the code is zigzag. It’s also easy to do it in R or Python, but both can’t be integrated by a Java main application. You can handle it in SPL (Structured Process Language) and call the result set from the Java main application. (About Java invocation of SPL scripts, see How to Call an SPL Script in Java)
A |
|
1 |
=file("source.txt").read@n() |
2 |
=A1.to(2,6) |
3 |
=A1.to(14,) |
4 |
=A2.regex("(.*) (.*)";a,b).(b) |
5 |
=A4.new(mid(~,1,1),mid(~,2,1),mid(~,3,1),mid(~,4,1),mid(~,5,1),mid(~,6,1),mid(~,7,1),mid(~,8,1),mid(~,9,1),mid(~,10,1),mid(~,11,1),mid(~,12,1),mid(~,13,1),mid(~,14,1),mid(~,15,1),mid(~,16,1),mid(~,17,1),mid(~,18,1),mid(~,19,1),mid(~,20,1)) |
6 |
=A3.regex("(.*) (.*)";a,b).(b) |
7 |
=A6.new(mid(~,1,1),mid(~,2,1),mid(~,3,1),mid(~,4,1),mid(~,5,1),mid(~,6,1),mid(~,7,1),mid(~,8,1),mid(~,9,1),mid(~,10,1),mid(~,11,1),mid(~,12,1),mid(~,13,1),mid(~,14,1),mid(~,15,1),mid(~,16,1),mid(~,17,1),mid(~,18,1),mid(~,19,1),mid(~,20,1)) |
8 |
=A5|A7 |
9 |
=A8.fno().(A8.field(~).concat()) |
A1: Read in each line of source.txt as a string and return them as a sequence.
A2: Get members from the 2nd one to the 6th one to generate a new sequence.
A3: Get members after the 14th (inclusive) one to generate a new sequence.
A4: Get desired data by matching members in A2 with a regular expression.
A5: Split A4’s sequence into a 2D table of the following structure.
A6: Get desired data by matching members in A3 with a regular expression.
A7: Split A6’s sequence into a 2D table of the following structure.
A8: Union A5’s 2D table and A7’s together.
A9: Join up values in each column into a string to make it a row.
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProc_SPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL