You've inherited a server that runs several apps which all output to the same log.
Your task is to de-interleave the lines of the log file by source. Fortunately, each line begins with a tag that indicates which app it is from.
Each line will look something like this:
[app_name] Something horrible happened!
- App tags are always between square brackets and will contain only alphanumeric characters and underscores.
- All lines will have an app tag at the beginning. There will not be preceding whitespace or any other characters.
- There will always be at least one space after the app tag
- App tags are nonempty
- There may be other square brackets later on any given line.
- There may or may not be a message after the tag
- The log may be empty
- There is no limit to how many unique app tags will be present in the file.
An entire log might look like this:
[weather] Current temp: 83F [barkeep] Fish enters bar [barkeep] Fish orders beer [stockmarket] PI +3.14 [barkeep] Fish leaves bar [weather] 40% chance of rain detected
Which should output three different logs:
[weather] Current temp: 83F [weather] 40% chance of rain detected
[barkeep] Fish enters bar [barkeep] Fish orders beer [barkeep] Fish leaves bar
[stockmarket] PI +3.14
You are not given the names of the app tags ahead of time. You must determine them only by analyzing the log file.
Rules and Scoring
- This is code-golf, so shortest code wins.
- Standard rules and loopholes apply
- Use any convenient IO format, provided that each input line is represented as a string, not a pre-parsed tag + message. Non-exhaustive list of allowed outputs:
- Several files named after each tag
- Several lists of strings
- One concatenated list of strings containing lines grouped by tag with or without a separator (the separator must not begin with a tag)
- Same as above, but to stdout or a file.
- The order in which separated logs are output is irrelevant, however the log lines within each group must preserve the order they were found in the original file