Extract lines from file, add to new files
Mats Wichmann
mats at wichmann.us
Thu Jan 11 13:45:27 EST 2024
On 1/11/24 11:27, MRAB via Python-list wrote:
> On 2024-01-11 18:08, Rich Shepard via Python-list wrote:
>> It's been several years since I've needed to write a python script so I'm
>> asking for advice to get me started with a brief script to separate names
>> and email addresses in one file into two separate files:
>> salutation.txt and
>> emails.txt.
>>
>> An example of the input file:
>>
>> Calvin
>> calvin at example.com
>>
>> Hobbs
>> hobbs at some.com
>>
>> Nancy
>> nancy at herown.com
>>
>> Sluggo
>> sluggo at another.com
>>
>> Having extracted salutations and addresses I'll write a bash script using
>> sed and mailx to associate a message file with each name and email
>> address.
>>
>> I'm unsure where to start given my lack of recent experience.
>>
> From the look of it:
>
> 1. If the line is empty, ignore it.
>
> 2. If the line contains "@", it's an email address.
>
> 3. Otherwise, it's a name.
>
4. Don't assume it's going to be "plain text" if the email info is
harvested from external sources (like incoming emails) - you'll end up
stumbling over a 誰かのユーザー from somewhere. Process as bytes, or be really
careful about which encodings you allow - which for email "names" is
something you can't actually control.
More information about the Python-list
mailing list