|
|
|
|
|
|
| Author |
Message |
aryzhov@spasu.net *nix forums addict
Joined: 17 Feb 2005
Posts: 64
|
Posted: Thu Jul 20, 2006 8:09 am Post subject:
Re: Match lines, group and sum
|
|
|
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
|
Posted: Thu Jul 20, 2006 7:58 am Post subject:
Re: Match lines, group and sum
|
|
|
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
|
Posted: Thu Jul 20, 2006 7:40 am Post subject:
Match lines, group and sum
|
|
|
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 |
|
 |
|
|
The time now is Thu Dec 04, 2008 4:25 am | All times are GMT
|
|
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
|
|