En Wed, 03 Sep 2008 06:16:03 -0300, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
escribi�:
I often grep particular patterns out of large logfiles and then
pipeline the output to sort and uniq -c
I thought today to knock up a script to do the counting in a python
dict.
This seems work in linux
$ cat count.py
#!/usr/bin/env python
import sys
from collections import defaultdict
accumulator=defaultdict(int)
for line in sys.stdin.readlines():
accumulator[line.strip()]+=1
print "contents,count"
for key in accumulator.keys():
print key,",",accumulator[key]
$ cat test | ./count.py
contents,count
, 1
23 , 1
1 , 1
3 , 2
2 , 2
5 , 3
When I try to run the same thing on windows I get
IOError: [Error 9] Bad file descriptor
How can I make this more windows friendly?
Explicitely invoking the interpreter worked for me. That is, these two
commands worked fine:
type test.txt | python count.py
python count.py < test.txt
But I cannot explain *why* it doesn't work the other way.
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list