Extract All Numbers from a Text File
Problem description & analysis
The following is text file txt.txt:
LOCATION
6 7
POINT
8 9
JOBS
1 4
4 9
11 8
9 6
5 2
We are trying to extract all numbers from the text file. Below is the desired result:
6
7
8
9
1
4
4
9
11
8
9
6
5
2
Solutions
Solution 1: Direct splitting
Write the following script (p1.dfx) in esProc:
A |
|
1 |
=file("result.txt").export(file("txt.txt").read().words@d()) |
Explanation:
A1 First read in the text file as a string; use @d option within words() function to extract numeric strings; and then export result to result.txt.
Solution 1: Using regular expression
Write the following script (p1.dfx) in esProc:
A |
|
1 |
=file("result.txt").export(file("txt.txt").read().regex("(\\d+)")) |
Explanation:
A1 First read in the text file as a string; use a regular expression to match numbers; and export result to result.txt.
https://stackoverflow.com/questions/61399911/split-a-text-file-based-on-title
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProcSPL
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