using System.Collections.Generic;
using System.Text.RegularExpressions;
static void Main(string[] args)
string responseBody = @"Apr 10 11:17:35 server ?shareLinkId=69dff0hb32a0nv
Apr 10 11:18:05 server ?shareLinkId=tosrvsdse4v8q8q
Apr 10 11:18:15 server ?shareLinkId=tosrvsdse4v8q8q
Apr 10 11:18:25 server ?shareLinkId=tosrvsdse4v8q8q
Apr 10 11:18:45 server ?shareLinkId=4esiramcsayu0
Apr 10 11:19:00 server ?shareLinkId=4esiramcsayu0
string result = ProcessLogs(responseBody);
Console.WriteLine(result);
Console.WriteLine($"Error: {ex.Message}");
static string ProcessLogs(string logs)
Dictionary<string, int> idCounts = new Dictionary<string, int>();
Regex regex = new Regex(@"\?shareLinkId=([a-zA-Z0-9]+)");
string[] lines = logs.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
foreach (string line in lines)
Match match = regex.Match(line);
string id = match.Groups[1].Value;
if (idCounts.ContainsKey(id))
List<string> resultList = new List<string>();
foreach (var kvp in idCounts)
string formattedId = kvp.Value > 1 ? $"{kvp.Key}:{kvp.Value}" : kvp.Key;
resultList.Add(formattedId);
return string.Join("\n", resultList);