LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-12-2007, 05:55 AM   #1
jagankumarmehta
LQ Newbie
 
Registered: Dec 2006
Posts: 6

Rep: Reputation: 0
Question grep regarding quiery...


Hi,
I have data in my logs file as given below.

year|month|date|hour|Circle|Error

2007|01|12|15|Kerala|PAMI Connection Error Exp-java.net.ConnectException: Connection refused
2007|01|12|15|Kerala|PAMI Connection Error Exp-java.net.ConnectException: Connection refused
2007|01|12|16|Karnataka|PAMI Connection Error Exp-java.net.ConnectException: Connection refused
2007|01|12|17|Delhi|PAMI Connection Error Exp-java.net.ConnectException: Connection refused
2007|01|12|11|Mumbai|PAMI Connection Error Exp-java.net.ConnectException: Connection refused
2007|01|12|11|Kerala|PAMI Connection Error Exp-java.net.ConnectException: Connection refused
2007|01|12|11|Kerala|PAMI Connection Error Exp-java.net.ConnectException: Connection refused
2007|01|12|12|Kerala|PAMI Connection Error Exp-java.net.ConnectException: Connection refused
2007|01|12|12|Kerala|PAMI Connection Error Exp-java.net.ConnectException: Connection refused
2007|01|12|13|Kerala|PAMI Connection Error Exp-java.net.ConnectException: Connection refused
2007|01|12|14|Kerala|PAMI Connection Error Exp-java.net.ConnectException: Connection refused
2007|01|12|18|Kerala|PAMI Connection Error Exp-java.net.ConnectException: Connection refused
2007|01|12|23|Kerala|PAMI Connection Error Exp-java.net.ConnectException: Connection refused
2007|01|12|10|Kerala|PAMI Connection Error Exp-java.net.ConnectException: Connection refused
2007|01|12|00|Kerala|PAMI Connection Error Exp-java.net.ConnectException: Connection refused

such type of data in my daily log files makes in thousands.
I want to kept the data circlewise & hour wise & take the count for that.Can anybody tell the oneliner command for that.So that i can take the count circlewise & hourwise.

Regards...
 
Old 01-13-2007, 02:01 AM   #2
osdeals
Member
 
Registered: Jul 2006
Distribution: RHEL, CentOS, PuppyLinux, SuSe, Ubuntu, Debian
Posts: 59

Rep: Reputation: 15
Please feel free to make any combination of the following commands to create a script that achieves you exact requirements.

1. cut (commonly used to make a text file be treated as a table with fields)
eg: cut -d"|" -f5 will give you just the "Circle". (-d = delimiter, -f = field)

2. sort
3. wc -l (used to count lines)

Hope that helps.
 
Old 01-15-2007, 01:34 AM   #3
jagankumarmehta
LQ Newbie
 
Registered: Dec 2006
Posts: 6

Original Poster
Rep: Reputation: 0
Question

But i have to take the count hourwise & circlewise.
I wants to redirect the output to html.That's why i need the oneliner command for taking the data from a file.
 
Old 01-15-2007, 02:37 AM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
What do you mean hourwise and circlewise? split by hour, and the hour sub-divided by circle, or two counts, one by hour (for any cycle), and one by cycle (for any hour)?

Here's one interpretation of your request, expressed as a small Perl program:
Code:
#!/usr/bin/perl -w

use strict;

my %hr;
my %ci;

while(<>){
        chomp;
        my @a=split(/\|/);
        if ( defined($hr{$a[3]}) ) { $hr{$a[3]}++ } else { $hr{$a[3]} = 1; }
        if ( defined($ci{$a[4]}) ) { $ci{$a[4]}++ } else { $ci{$a[4]} = 1; }
}

foreach my $k (keys %hr) {
        printf("hour %-3s has a count of: %d\n", $k, $hr{$k});
}

foreach my $k (keys %ci) {
        printf("circle %-10s has a count of: %d\n", $k, $ci{$k});
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 04:56 AM
Quiery database and show results on a web page jlinkels Linux - Software 5 01-04-2007 07:26 AM
grep: grep for two substrings? eur0dad Linux - General 2 08-17-2006 04:03 PM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration