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?
Thanks
Neil 4 4850
En Wed, 03 Sep 2008 06:16:03 -0300, zu*****@gmail.com <zu*****@gmail.com>
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
Gabriel Genellina wrote:
En Wed, 03 Sep 2008 06:16:03 -0300, zu*****@gmail.com
<zu*****@gmail.comescribi�:
>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.
Known bug in NT-based file association. I'll try
to find an online reference, but that's basically
what it comes to. I think you can faff-about with
batch files to achieve the effect, but I can't
quite remember. http://support.microsoft.com/kb/321788
TJG
On Sep 3, 11:16*pm, Tim Golden <m...@timgolden.me.ukwrote:
Gabriel Genellina wrote:
En Wed, 03 Sep 2008 06:16:03 -0300, zugn...@gmail.com
<zugn...@gmail.comescribi :
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.
Known bug in NT-based file association. I'll try
to find an online reference, but that's basically
what it comes to. I think you can faff-about with
batch files to achieve the effect, but I can't
quite remember.
http://support.microsoft.com/kb/321788
TJG
Thanks.
I'll ues the explicit python call.
En Wed, 03 Sep 2008 07:16:12 -0300, Tim Golden <ma**@timgolden.me.uk>
escribi�:
Gabriel Genellina wrote:
>En Wed, 03 Sep 2008 06:16:03 -0300, zu*****@gmail.com <zu*****@gmail.comescribi�:
>>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.
Known bug in NT-based file association. I'll try to find an online
reference, but that's basically
what it comes to. I think you can faff-about with
batch files to achieve the effect, but I can't
quite remember.
http://support.microsoft.com/kb/321788
Uhmm... That KB article says the bug was corrected in Windows XP SP1, but
I have SP3 installed and the test failed. Updating the registry by hand
solved the problem. A regression maybe?
--
Gabriel Genellina This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jeff Learman |
last post by:
I want to do a very simple thing in Windows. (Using Python Shell.)
I want to write a prompt to sys.stdout and read the user input.
(Ideally, without waiting for a newline.)
Here are the...
|
by: Brent W. Hughes |
last post by:
I'd like to get a character from stdin, perform some action, get another
character, etc. If I just use stdin.read(1), it waits until I finish typing
a whole line before I can get the first...
|
by: Joe Burnett |
last post by:
Hello,
I am using the following perl read function to read form information
from a client web page:
read(STDIN, $GN_QUERY, 100);
Everything works fine on a Linux/Apache server. I get the...
|
by: lickspittle |
last post by:
Hi,
I have Python embedded with my other code, and when my other code opens
a console and redirects stdout, stdin and stderr to it, then calls
PyRun_InteractiveLoop, it immediately returns with...
|
by: Mike Tammerman |
last post by:
Hi,
I want create a subprocess using Popen and pipe some input to it.
Although everything works perfectly while executing python in, it
doesn't work if I try with executables made by py2exe.
...
|
by: Harayasu |
last post by:
Hi,
Using fgets() I can read from stdin and with fputs() I can write to
stdout. Now I have two programs, one writing to stdin and the other
one reading from stdin. And I would like the second...
|
by: Charlie Zender |
last post by:
Hi,
I have a program which takes the output filename argument from stdin.
Once the program knows the output filename, it tries to open it.
If the output file exists, the program asks the user to...
|
by: Dmitry Anikin |
last post by:
I want to read stdin in chunks of fixed size until EOF
I want to be able (also) to supply data interactively in console
window and then to hit Ctrl+Z when finished
So what I do is:
while True:...
|
by: hg |
last post by:
Hi,
Is there a way ? ... select ?
hg
|
by: kimonp |
last post by:
I am running on windows XP with a fresh install of wamp5 (1.7.2) and mediawiki.
I am trying to call a perl function from within php using proc_open.
The perl script is being executed and...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |