aspose file tools*
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 Java 8 in Action this week in the Java 8 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: 24168
    
  30

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: 24168
    
  30

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Needs help for grouping data
 
Similar Threads
Remove unwanted text from a big text file
Java Issue
Need help for Shell Script to reduce a file
Problem while staring application.. A WebGroup/Virtual Host to handle /s1gcb/logon/sbusePlz help me
error connecting to SQL Server 2005