✅ 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
SCShocked from Human Resources
why not use JSON :SCshocked:
Angius
Angius3mo 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
chimera3mo 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.Mentia3mo 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 Dale3mo ago
How would I use the Variables after?
Angius
Angius3mo ago
Like, uh, any other variable?
D.Mentia
D.Mentia3mo ago
match.Groups["X0"], "Time", etc as named in the regex
Christian Dale
Christian Dale3mo 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
More Posts
I just published an update to Azure, but for some reason the header access-control-allow-headersWhen using Azure Web App, for some reason i can't add the access-control-allow-headers header. I eveSegmentation fault using Debian Bookworm ARM64v8 image during dotnet restore in dockerI'm getting a strange error named "Segmentation fault (core dumped)" when trying to build my dockerf✅ How to get value of DatePicker from nested UserControl Avalonia```xml <!-- in new user view --> <UserControl xmlns:uc="clr-namespace:MathGame.Views.UserControls;as✅ Styling Avalonia DatePicker ControlMy Code: https://pastebin.com/v057vZCS Avalonia Code For DatePicker Style: https://pastebin.com/Qewx✅ Key bind for closing a console program while console/visual studio is out of focusHello, I wonder if there is a key bind that closes/stops a running program in Visual studio. It is Powershellwhy i cannot delete powershell, or add file in drivers folder (I think the reason is the same) by c#I want to make a dynamic compiler of c# code and with that have a console on the web page, using thiI want to make a dynamic compiler of c# code and with that have a console on the web page, using thiDownloading and extracting a .7z file from within a WinUI applicationI'm currently developing an application installer using WinUI3, and I'm stuck at the part where the Steel Battalion controller lightsHello. I need some help figuring out how to do one of two things with my Steel Battalion controller.C# WinForms ChatI'm looking to make a chat application where users can send chats over a server. I already have a s