I have a log file sitting in UNIX server which is a combination of ERROR and CRIT in a random order. I want to group all ERROR together and all CRIT together. And there are so many lines for each ERROR and CRIT. I just want to capture only main error description line from each ERROR and CRIT to reduce the file. I have to write unix script to handle this. I am very new to UNIX and before writing script I want to write an algorithm for that. I am wondering if someone can show me the algorithm for this.
Note sure what you mean by "algorithm" here. The egrep command filters out only those lines that start with ERROR ("^ERROR") or ("|") start with CRIT ("^CRIT").Those lines are then piped to the sort program, which will group lines starting with the same keywords together.