You can get the results in rows at a time with Linq (here I use the method notation):
string[] lines = File.ReadAllLines("input.txt"); var result = lines.Where(line => line.Substring(0, 6) == "RECORD") .Select(line => line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)) .GroupBy(columns => columns[1], columns => columns[2] + "/" + columns[3]) .Select(group => group.Key + " " + string.Join(", ", group.ToArray()));
Output:
DEVON 1/6748, 2/9123, 3/3723, 4/3732, 5/3723, 6/3723 JASON 1/7436, 2/9123, 3/9123 SHERRIE 1/6434, 2/6434, 3/9123
It's hard for me to wrap rows in columns without the standard Zip function. Maybe this is good enough for you? If not, then you will probably have to make the last bit using a helper method that iterates over the individual IEnumerables.
source share