*
The moose likes Linux / UNIX and the fly likes Needs help for grouping data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Needs help for grouping data" Watch "Needs help for grouping data" New topic
Author

Needs help for grouping data

Sam Saha
Ranch Hand

Joined: Jan 23, 2010
Posts: 104
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.

The log file looks like this:


I want the output like this:

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

grep for lines that start with one of your keywords, then sort the result:



[Jess in Action][AskingGoodQuestions]
Sam Saha
Ranch Hand

Joined: Jan 23, 2010
Posts: 104
I would appreciate if you could show the algorithm for that.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.
 
Consider Paul's rocket mass heater.
 
subject: Needs help for grouping data
 
Similar Threads
Need help for Shell Script to reduce a file
error connecting to SQL Server 2005
Java Issue
Remove unwanted text from a big text file
Problem while staring application.. A WebGroup/Virtual Host to handle /s1gcb/logon/sbusePlz help me