reachvimalm (11) Mar 20, 2010 at 3:29am UTC
How would you count word in file. remember you can't use grep with wc because it won't count word coming twice in same line.
Bazzy (4111) Mar 20, 2010 at 3:29am UTC
Why are you asking this in a C++ forum?
writetonsharma (832) Mar 20, 2010 at 3:29am UTC
I can do it in perl.. :D
chrisname (2545) Mar 20, 2010 at 3:29am UTC
I can do it in Python... :D
Bazzy (4111) Mar 20, 2010 at 3:29am UTC
I can do it in Brainfuck!
No, I can't D:
computerquip (876) Mar 20, 2010 at 3:29am UTC
LOLCODE ftw.
And I've never used wc. What does it do?
Last edited on Mar 20, 2010 at 3:29am UTC
chrisname (2545) Mar 20, 2010 at 3:29am UTC
Counts words, chars or lines in a file or files. At first I thought it only accepted one file; so I wrote my own version.
Two hours later I man'd it and discovered I was wrong...
Last edited on Mar 20, 2010 at 3:29am UTC
computerquip (876) Mar 20, 2010 at 3:29am UTC
so wouldn't "cat <filename> | wc" work?
Last edited on Mar 20, 2010 at 3:29am UTC
chrisname (2545) Mar 20, 2010 at 3:29am UTC
No idea... I've not delved very deep into the shell yet. I'm still trying to scratch the surface out of the way so I can get to the softer core.
Grey Wolf (1609) Mar 20, 2010 at 3:29am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#! /bin/sh
# Read a text stream on standard input, and output a list of
# the n (default: 25) most frequently occurring words and
# their frequency count, in order of descending counts, on
# standard output.
#
# Usage:
# wf [n]
tr -cs A-Za-z\' ' \n' |
tr A-Z a-z |
sort |
uniq -c |
sort -k1,1nr -k2 |
sed ${1:-25}q
./wf 10 < testdoc
4 a
4 i
4 the
3 queue
3 to
2 am
2 global
2 is
2 within
1 and
reachvimalm (11) Mar 20, 2010 at 3:29am UTC
amazing 'Grey wolf'. but its too complex. I tried it and it works. can't there be better solution. an easy one. ;)
Grey Wolf (1609) Mar 20, 2010 at 3:29am UTC
Ooops, misread your requirements, for some reason I thought you wanted to count how many of each individual word there are.
Edit:
Actually I'm not sure what your exact requirements are, can you elucidate?
Last edited on Mar 20, 2010 at 3:29am UTC
reachvimalm (11) Mar 20, 2010 at 3:29am UTC
you have done better than needed.
e.g.
"white dog may or may not run fast.
It may rain today."
here "may" comes twice in same line and once in other line. I just want to find out how many counts of "may" are.
This topic is archived - New replies not allowed.