On 12/18/2017, at 01:34, Rick Gordon <[email protected] 
<mailto:[email protected]>> wrote:
> ...
> So what I'm wondering is how to determine how many addresses in this OR 
> formation I could chain before making my search string get too long.
> 
> I'd also be interested to know what other approaches I might consider for 
> trimming a list of one email address per line, removing addresses from a list 
> of invalid or unsubscribed addresses.


Hey Rick,

Don't mess with find/replace — use a text-filter.

Here are several options (although I'd probably go with the Perl).

(Make sure you have backups before testing any given solution.)


NOTE - in the sed filters you need to escape any special characters in the 
email address, and the easiest way to do that is to use Cmd-E to enter it into 
BBEdit's Find dialog, open the dialog, and copy it out again.


This will leave a hole everywhere a deletion is made, so you can see them.

#!/usr/bin/env bash

sed -E '
    s!smitj1234@students\.uwc\.edu!!g
    s!jane\.smith@uwc\.edu!!g
'


If you have a one per line listing of email addresses then this will delete the 
given line.


#!/usr/bin/env bash

sed -E '
    /smitj1234@students\.uwc\.edu/d
    /jane\.smith@uwc\.edu/d
'


Simplest — No escaping needed:


If you want to delete a list of literal email address strings sourced from a 
“delete file” in the currently open BBEdit window:

#!/usr/bin/env bash

emailsToRemoveFilePath=~/'Downloads/Email Address to Remove.txt'
grep -Fvxf "$emailsToRemoveFilePath"

** You can use this same command with a file instead of a window, but you have 
to run the filter as a script rather than as a text-filter.


Best?  Certainly the fastest for big files.

NOTE - the single quotes in the path strings.  If you path has any spaces in it 
you either have to quote it or escape the spaces.  I find quoted paths much 
easier to read.


#!/usr/bin/env perl -sw

my $validEmails = glob("~/'Downloads/Valid Email Addresses.txt'");
my $invalidEmails = glob("~/'Downloads/Invalid Email Addresses.txt'");
 
# Open the files.
open F1 , "$validEmails" or die "Cant open : $! \n" ; 
open F2 , "$invalidEmails" or die "Cant open : $! \n" ; 

# Create the hash key with each line of the invalid items file.
while (<F2> ) { 
        chomp; 
        $file{$_}='';
} 

# Print the line from the valid emails file — IF key does not exist in the hash.
while (<F1> )  { 
        chomp ; 
        print $_ , "\n"   unless(exists ( $file{$_} ) ) ; 
} 


You can run the above Perl script via Cmd-R and get non-destructive output.

OR — you can run it as a text filter ON the valid email address file (in the 
front BBEdit window).


Here's one way to do it with AppleScript and the Satimage.osax 
<http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html>.

-------------------------------------------------------------------
# REQUIRES the Satimage.osax --> http://tinyurl.com/satimage-osaxen 
<http://tinyurl.com/satimage-osaxen>
-------------------------------------------------------------------

# Establish the file aliases.
set invalidFile to alias ((path to downloads folder as text) & "Invalid Email 
Addresses.txt")
set validFile to alias ((path to downloads folder as text) & "Valid Email 
Addresses.txt")

# Scoop up the valid and invalid email addresses.
set invalidEmails to find text "^\\S+@\\S+" in invalidFile with regexp, all 
occurrences and string result
set validEmails to find text "^\\S+@\\S+" in validFile with regexp, all 
occurrences and string result

# Remove invalid addresses from the valid list.
set newList to change invalidEmails into "" in validEmails with regexp without 
case sensitive

# Output the new valid addresses to the console
set AppleScript's text item delimiters to linefeed
set newList to newList as text
set newList to change "^$[[:blank:]]*$\\R?" into "" in newList with regexp 
without case sensitive

# Get file parent folder.
tell application "Finder" to set fileParent to parent of validFile as text

# Create new valid address file path.
set newValidAddressFile to fileParent & "New Valid Email Addresses - " & 
(strftime (get current date) into "%Y.%m.%d · %H.%M.%S.txt")

# Write the new file.
set newFile to writetext newList to file newValidAddressFile

-------------------------------------------------------------------

After thinking about it I'd do this differently — I'd make a duplicate of the 
valid file and then do the replacements directly in the file.


--
Take Care,
Chris


-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/bbedit.

Reply via email to