That is a nice problem you have. Still, it's not defined enough to solve it. You only specified the input, and the output format, but not the output itself. You also did not provide any parsing rules.
Taking what you have written as it stands, you could just run a simple substitution on every log line, substituting ">" with "," and you have a comma separated csv. This is exactly what you have written, but probably not exactly what you want.
I could make some assumptions. Let's assume that you want to extract the user names and the message. Where are they? Well, maybe the rules are as follows:
#!/usr/bin/perl use v5.14; my $input_line = 'T 1310234540 19<24SomeUserName>19 This is user chat. + '; $input_line =~ m/ \< # after the '<' sign, and \d+ # any digits that follow it, (\w+) # capture all letters as $1 \> # then expect the '>' sign \d+\s+ # followed by some other digits and whitespace (.+) # everything that follows is the message /x; my $username = $1; my $message = $2; say "Username: [$username], Message: [$message]";
But are those the correct rules? What if the user name is '1983_Mike'? Will his name be parsed correctly, or will it just be "Mike"? It won't be either of those. Maybe the user names cannot contain anything other than letters? Maybe not. What if the numbers before the message have their own meaning? Does 19 mean that it's the 19th message sent by SomeUserName in this session? Is it important? Should it form part of your desired output?
Start by asking yourself those questions, and figuring out what you want to do, exactly. Then, you could use the code above as a starting point, and look at the relevant sections of perlintro, as per the suggestion that was already given.
Good luck, and don't forget that the chat messages can probably contain commas.
regards,
Luke Jefferson
In reply to Re: Parse Chat Log to CSV
by blindluke
in thread Parse Chat Log to CSV
by Redfish76
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |