✅ Looking for a way to Extract information from a txt File

Looking to Extracting Particular Information form the Log File. The Information I would like to extract is look for a Particular IP and read the Number of Alarms and then store the X & Y Co-Ords for that number of Alarms. e.g. Looking for IP 10.247.247.11 It would return
IP:10.247.247.11
Time: 2024-02-18 07:51:04
Alarm: 1
X: 845
Y:596
Size: 335
Time: 2024-02-18 07:51:04
Alarm 2
X:845
Y:596
Size:335
X:852
Y:548
Size: 100
IP:10.247.247.11
Time: 2024-02-18 07:51:04
Alarm: 1
X: 845
Y:596
Size: 335
Time: 2024-02-18 07:51:04
Alarm 2
X:845
Y:596
Size:335
X:852
Y:548
Size: 100
I will be using the XY Co-ords to draw onto an image.
8 Replies
The Fog from Human Resources
why not use JSON :SCshocked:
Angius
Angius9mo ago
Using a proper structured file format would definitely be better, yes Failing that, you'll need a simple line parser Loop over all the lines. If the line starts with Alarm, create a new Alarm. Then, when the line starts with X, set that alarm's X, and so on
chimera
chimera9mo ago
Parse each line https://stackoverflow.com/a/8038746 and you could just put everything before your : into the key in a Dictionary<string, string> and everything after into the value. That way you can easily access the values in memory
Stack Overflow
What's the fastest way to read a text file line-by-line?
I want to read a text file line by line. I wanted to know if I'm doing it as efficiently as possible within the .NET C# scope of things. This is what I'm trying so far: var filestream = new Syste...
D.Mentia
D.Mentia9mo ago
Why not regex? Sometimes can be slow, depends on size of the file but you can kinda get it all at once into reasonably well named groups [\s]+(?<Time>[0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+\.[0-9]+) .*10\.247\.247\.11 .*(?<AlarmNum>[0-9+])[\s]+.*x = (?<X0>[0-9\.]+)[\s]+\.y = (?<Y0>[0-9\.]+)\s+\.sz = (?<Size0>[0-9]+)[\s]+.*x = (?<X1>[0-9\.]+)[\s]+\.y = (?<Y1>[0-9\.]+)\s+\.sz = (?<Size1>[0-9]+)[\s]+.*x = (?<X2>[0-9\.]+)[\s]+\.y = (?<Y2>[0-9\.]+)\s+\.sz = (?<Size2>[0-9]+)[\s]+.*x = (?<X3>[0-9\.]+)[\s]+\.y = (?<Y3>[0-9\.]+)\s+\.sz = (?<Size3>[0-9]+)
No description
Christian Dale
Christian DaleOP9mo ago
How would I use the Variables after?
Angius
Angius9mo ago
Like, uh, any other variable?
D.Mentia
D.Mentia9mo ago
match.Groups["X0"], "Time", etc as named in the regex
Christian Dale
Christian DaleOP9mo ago
How can I use the Variable of IP into the Regex pattern? The IP is stored as IP = "10.247.247.11"
Want results from more Discord servers?
Add your server