Counting occurrences

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
gcotterl
Posts: 255
Joined: Wed Mar 10, 2004 8:43 pm
Location: Riverside California USA

Counting occurrences

Post by gcotterl »

How can I get TextPad to count the number of times "68" occurs in a file?

(Note: "68" may occur multiple times in a row).
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Find what: 68
Replace with: 68

Replace All
Look at the left-hand end of the status line. Undo the action to restore the previous state.
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

I need a TextPad macro to insert the statistics including a count of string occurrences.

How to capture that count from the lower left corner and include it in the document with other specs inserted with Edit/Insert/Statistics?

I cannot find any command that returns a string count except in the status line.
Hope this was helpful.............good luck,
Bob
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

There's no way to do this within TextPad that I'm aware of.

It's another job for a one-line script. E.g.

Code: Select all

perl -ne "$n ++ while /text_to_search_for/g ; END { print $n }" filename
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Thanks ben_josephs for confirming my fear.

Guess I could run the perl script as a tool, direct the result to a file and do a copy/paste all within the same macro. Will have to pull out my old perl stuff that I have not looked at in years.

Thanks for the suggestion.
Hope this was helpful.............good luck,
Bob
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Unfortunately, TextPad won't let you run a tool in a macro. Strange and sad, but true.

If you can get the tool to send its output to the clipboard you can do what you want in two steps: run the script and paste its result into your document.

You can get the script's output onto the clipboard either by redirecting it there (e.g., by calling Perl from 4NT (perl whatever.pl > clip:)) or by getting the script itself to send its output there (e.g. by using the Perl module Win32::Clipboard).

Alternatively, you can use a keyboard stuffer such as AutoIt or MacroScheduler to send key strokes to TextPad that run the tool and paste the output. Or you can do it from within the script itself, using the Perl module Win32::GuiTest.
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Thanks again for the options.

I already made a Macro Scheduler macro to read the file in TextPad, and to do the counting and pasting for me.
Hope this was helpful.............good luck,
Bob
Post Reply