Does anyone know a good program to count text

TrukinDave

Diamond Member
Feb 10, 2005
3,197
0
76
Hello

I am looking for a program to count numbers in a text file: I have found a couple but they dont count the way I am needing. The program has about 800,000 numbers that needs to be counted:

Here is a example of what I am needing a program to count:
Take this text:

10 20 30 40 10 60 70 10
20 30 20 20
5 5 5 5 5 5

Results I am needing

5 X 6
10 X 3
20 X 4
30 X 2
40 X 1
60 X 1
70 X 1

Most will count like this: These I cannot use

18 Counts entire text

or

0 X 12
1 X 3
2 X 4
3 X 3
4 X 1
5 X 6
6 X 1
7 X 1
 

Aldon

Senior member
Nov 21, 2013
449
0
0
I wrote a small script, although you'd have to reformat your text file a little more, for some reason. An example:

numbers.txt (2 lines, single-digit numbers next to two-digit numbers):

Code:
10 20 30 40 10 60 70 10
20 30 20 20 5 5 5 5 5 2 2 2 6 6 6 8 8 8

And then the code:

PHP:
<?php

// Loads file, and separates each number by a space

$numbers = file_get_contents('numbers.txt');
$sep     = explode(' ', $numbers);
$arr = array();

for ($i = 0; $i < count($sep); $i++)
{
	array_push($arr, $sep[$i]);
}

function findNumber($num, $array)
{
	$counter = 0;
    foreach ($array as $key => $value) 
    {
	   if ($value == $num)
	   {
		  $counter++;
	   }
    }

    return $num .' X '. $counter;
}

// The first parameter is the specific number (you want to know how many times it occurs)

echo findNumber(70, $arr);


?>

Not awesomely written, and you could obviously write it in OOP, but that would be a waste of time (in my opinion). Hope that works.
 

code65536

Golden Member
Mar 7, 2006
1,006
0
76
you could obviously write it in OOP

That would be like building a tank to kill a mouse.

Here, have a Perl 2-liner:
Code:
map { map { ++$counts{$_} } split(/\s+/) } (<STDIN>);
map { print "$_ x $counts{$_}\n" } (sort { $a <=> $b } keys %counts);
(accepts any number of lines of text, with numbers delimited by any number of whitespace chars)

Sample usage/output:
Code:
C:\Temp>type numbers.txt
10 20 30 40 10 60 70 10
20 30 20 20
5 5 5 5 5 5

C:\Temp>foo.pl < numbers.txt
5 x 6
10 x 3
20 x 4
30 x 2
40 x 1
60 x 1
70 x 1
 
Last edited:

TrukinDave

Diamond Member
Feb 10, 2005
3,197
0
76
Sorry its taking me this long to reply back I am a truck driver and have been out for a while.

I am not a programmer LOL. I wouldn't know what to do with those codes on my best day

Is here a program that can be downloaded that can do that, I always wanted to learn programming just never had the time.

Thanks for any help
 
Feb 25, 2011
16,823
1,493
126
You might be able to work something out in Excel, but otherwise, not really.

I guess my best guess would be to open it in Word, and manually do a find/replace for each possible number. (replace all occurrences of "20" with "20", make sure you have the "whole words only" checkbox checked.)

It will report the number of replacements made, which is the number of occurrences in the document.
 

code65536

Golden Member
Mar 7, 2006
1,006
0
76
Out of curiosity, why did you request that the output be in a specific format, then? That usually is needed only when you need to feed the results into some other script or program...

In any case, the Perl option is still by far the easiest, even for someone who has never touched code in their life.

1) Copy and paste the 2 lines of Perl code into Notepad and save it with a .pl file extension, e.g., counter.pl

2) Install ActivePerl (I assume you're on Windows?)

3) Dump the numbers you want counted into a text file, e.g., numbers.txt; for convenience, save it in the same directory as counter.pl

4) Open a command prompt in the directory containing counter.pl, and type counter.pl < numbers.txt
 
Last edited:

KillerBee

Golden Member
Jul 2, 2010
1,753
82
91
Out of curiosity, why did you request that the output be in a specific format, then? That usually is needed only when you need to feed the results into some other script or program...

In any case, the Perl option is still by far the easiest, even for someone who has never touched code in their life.

1) Copy and paste the 2 lines of Perl code into Notepad and save it with a .pl file extension, e.g., counter.pl

2) Install ActivePerl (I assume you're on Windows?)

3) Dump the numbers you want counted into a text file, e.g., numbers.txt; for convenience, save it in the same directory as counter.pl

4) Open a command prompt in the directory containing counter.pl, and type counter.pl < numbers.txt

That was a neat 2 liner you wrote code65536
installed ActivePerl and worked like you said.

Then installed their 15 day trial Perl Dev Kit to make a standalone executable and that worked.

Are there any free versions (either Linux or Windows)
to convert perl scripts into standalone Windows executeables ?
 

code65536

Golden Member
Mar 7, 2006
1,006
0
76
That was a neat 2 liner you wrote code65536
installed ActivePerl and worked like you said.

Then installed their 15 day trial Perl Dev Kit to make a standalone executable and that worked.

Are there any free versions (either Linux or Windows)
to convert perl scripts into standalone Windows executeables ?

The PDK isn't really a compiler--all it does is take your Perl script and bundle it with their Perl interpreter into a single file. If you run a PDK-created executable, you'll notice that it actually extracts some temp files as it is run. So, given that, it should be relatively easy for someone to make their own "compiler" if they really felt such an urge.
 

KillerBee

Golden Member
Jul 2, 2010
1,753
82
91
So, given that, it should be relatively easy for someone to make their own "compiler" if they really felt such an urge.

relatively easy for who ?

(they sure packed a lot into a final 1.2mb file)


edit:
installed PARacker into Activestate and it seems to work just as well
-the smile popped in there on its own
 
Last edited:

code65536

Golden Member
Mar 7, 2006
1,006
0
76
relatively easy for who ?

(they sure packed a lot into a final 1.2mb file)


edit:
installed PAR:Packer into Activestate and it seems to work just as well
-the smile popped in there on its own

Yes, the PDK creates quite a large executable because of everything that it has to bundle. It also bundles any external Perl modules that a script references, as well as their dependencies, in which case, it can become even larger. You can mitigate this somewhat by running it through UPX afterwards.

(Also, "relatively easy", as in, compared to the alternatives like making a real compiler, a bundle/wrapper around an existing interpreter is, relatively speaking, very easy.)
 

KillerBee

Golden Member
Jul 2, 2010
1,753
82
91
now I just got to figure out how your 2 lines of code do what they do
I'm almost able to understand Aldon's code but have no idea how yours works
 
Last edited:

code65536

Golden Member
Mar 7, 2006
1,006
0
76
now I just got to figure out how your 2 lines of code do what they do
I'm almost able to understand Aldon's code but have no idea how yours works

Perl (which was designed by someone with background in linguistics) can be like poetry. There are many ways to express something, and there can be a lot of meaning that is implicit and subtle.

Python is like a technical whitepaper. The style is strict, much of it is explicit, and Python tries to avoid having many different ways of expressing / doing the same thing.

If you have to understand and maintain someone else's code, Python is the best. But it's also a boring, stifling language. Perl can be beautiful (sigils not withstanding), but trying to understand someone's Perl code can sometimes be like trying to parse the meaning of a poem in English class. For better or for worse (and sadly, most people think worse), Perl is the programming language that comes closest to the flexibility of human language. (Perl can also be boring and dry--it depends on how it's written. But at least it offers you that freedom to choose.)

Anyway, this should help you get started.
 
Last edited:

sonitravel09

Senior member
Jun 25, 2014
217
4
46
TextPad will do that. You can view properties for your current file and see a word count, edit/insert a line of statistics that includes word count and more.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |