niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » shell
Match lines, group and sum
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
aryzhov@spasu.net
*nix forums addict


Joined: 17 Feb 2005
Posts: 64

PostPosted: Thu Jul 20, 2006 8:09 am    Post subject: Re: Match lines, group and sum Reply with quote

Quote:
any ideas?

sort | uniq -c | while read first junk;do echo $junk "($first times)";
done

just an idea, not tested
Back to top
Chris F.A. Johnson
*nix forums Guru


Joined: 20 Feb 2005
Posts: 2268

PostPosted: Thu Jul 20, 2006 7:58 am    Post subject: Re: Match lines, group and sum Reply with quote

On 2006-07-20, FriesAOLE wrote:
Quote:
Hi,
I've a sequence of line in a file, that is a result from a parsing of a
logfile. I would group equal lines, and then count them, group by
group.
For example:

file example:
xxx.xxx.xxx.xxx - access granted
xxx.xxx.xxx.xxx - access granted
yyy.yyy.yyy.yyy - access granted
zzz.zzz.zzz.zzz - access denied

wish of output:

xxx.xxx.xxx.xxx - access granted 2 time(s)
yyy.yyy.yyy.yyy - access granted 1 time(s)
zzz.zzz.zzz.zzz - access denied 1 time(s)

awk '{ ++x[$0] } END { for ( l in x ) print l, x[l], "time(s)" }'

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Back to top
FriesAOLE
*nix forums beginner


Joined: 20 Jul 2006
Posts: 1

PostPosted: Thu Jul 20, 2006 7:40 am    Post subject: Match lines, group and sum Reply with quote

Hi,
I've a sequence of line in a file, that is a result from a parsing of a
logfile. I would group equal lines, and then count them, group by
group.
For example:

file example:
xxx.xxx.xxx.xxx - access granted
xxx.xxx.xxx.xxx - access granted
yyy.yyy.yyy.yyy - access granted
zzz.zzz.zzz.zzz - access denied

wish of output:

xxx.xxx.xxx.xxx - access granted 2 time(s)
yyy.yyy.yyy.yyy - access granted 1 time(s)
zzz.zzz.zzz.zzz - access denied 1 time(s)

any ideas?
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
The time now is Thu Dec 04, 2008 4:25 am | All times are GMT
navigation Forum index » Programming » shell
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts blocking mails with long lines and giberish Dale Blount Postfix 4 Thu Jul 20, 2006 2:31 pm
No new posts Match pattern in ksh script lnrntx@gmail.com shell 6 Thu Jul 20, 2006 1:48 am
No new posts authentication for group question Luis P. Mendes Slackware 3 Wed Jul 19, 2006 6:15 pm
No new posts Bug#378907: ITP: tet -- Test Environment Toolkit from the... Stuart Anderson devel 0 Wed Jul 19, 2006 5:10 pm
No new posts Reading long lines doesn't work in Python Scott Simpson python 2 Wed Jul 19, 2006 4:25 pm

Credit Cards | Loans | Per Insurance | Ken follet | Web Development
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1096s ][ Queries: 20 (0.0399s) ][ GZIP on - Debug on ]