Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > count
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 7 Topic 2114 of 2317
Post > Topic >>

count

by "Luuk" <luuk@[EMAIL PROTECTED] > Dec 24, 2007 at 03:50 PM

Hi,

I created a little script, because i needed some functionality that i
didnot 
know of how to do it in another way

the script: (stored in a file named 'count')
#!/bin/awk -f

{
        if (a==$0) {
                i++;
        } else {
                if (a=="") {
                        ++i;
                } else {
                        print a, ++i;
                }
                i=0;
                a=$0;
        }
}

END { print a, ++i; }


With this script i can do this:
if i have a textfile with these contents:
aaaa
aaaa
aaaa
bbb
bbb
cccc
cccc
cccc
cccc
the output of 'count textfile' will be:
aaaa 3
bbb 2
cccc 4
(so, basically counting the different values)

Does anyone have a clue if there is a 'standard' util/tool under linux
which 
can do this?
(because i think this simple/basic functionality could be usefull 
sometimes...)


-- 
Luuk
 




 7 Posts in Topic:
count
"Luuk" <luuk  2007-12-24 15:50:13 
Re: count
gazelle@[EMAIL PROTECTED]  2007-12-24 14:59:34 
Re: count
"Luuk" <luuk  2007-12-24 16:15:44 
Re: count
gazelle@[EMAIL PROTECTED]  2007-12-24 16:32:54 
Re: count
"Luuk" <luuk  2007-12-24 18:18:28 
Re: count
Ed Morton <morton@[EMA  2007-12-24 10:33:02 
Re: count
jmh <jmhall@[EMAIL PRO  2007-12-24 22:16:24 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 0:46:19 CDT 2008.