Hello Harvey... Wow. This is very kind of you. Thank you! 

I hope to take some time this weekend to see if I can make this work. I'll 
let you know how it goes.

Zoe

On Wednesday, 23 June 2021 at 05:22:31 UTC+3 Harvey Pikelberger wrote:

>
> On Jun 22, 2021, at 12:59 PM, Zoe Barnett <[email protected]> wrote:
>
>  As neither bear nor mouse. I need to count distinct words or exact 
> phrases separated by spaces on either side or followed by punctuation like 
> , : ; .  So 
> popular pet,
> (followed by a comma) would get a hit, but
> popular petshops
> wouldn't.
>
>
> There are a lot of ways to approach this.
> The BBEdit folks are brilliant w/ AppleScript and integrating that with 
> BBEdit.
> There are also ways to approach this using command line which is very 
> fast, a little cryptic.
> Here's a very simple, probably overly simple NodeJS approach, which can be 
> modified to work in a web browser.
> You would no doubt customize this to suit the nuances and particulars of 
> your workflow.
>
> fs = require('fs'); //file handling library for NodeJS
> wordList = fs.readFileSync(__dirname + '/list.txt').toString().trim().
> split('\n'); //get the values in "list.txt"
> content = ' ' + fs.readFileSync(__dirname + '/content.txt').toString().
> trim() + ' '; //gets the content
> output = []; //initialize output variable
> wordList.forEach(thisSearch => { //iterate through your list of words
> var thisRegex, thisRslt, thisCount;
> thisRegex = new RegExp('[^a-zA-Z]' + thisSearch + '[^a-zA-Z]', 'g'); //Set 
> up the search / count
> thisRslt = content.match(thisRegex); // execute the count
> thisCount = (thisRslt == null ? 0 : thisRslt.length); // turn "null" 
> results into zero
> console.log(thisSearch, thisCount, thisRslt); //progress outputted to 
> console
> output.push(thisSearch + "\t" + thisCount); //add to the output variable
> });
> fs.writeFileSync(__dirname + '/output.txt', output.join('\n')); //puts 
> the final result in a file named "output.txt"
>
>
>
>
>

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "[email protected]" rather than 
posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/cd0e36f3-6286-470d-a6dd-f06d3cd2aca3n%40googlegroups.com.

Reply via email to