Need Help Adjusting Lines

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
bad959fl
Posts: 21
Joined: Wed Jun 15, 2005 11:32 pm

Need Help Adjusting Lines

Post by bad959fl »

I have a mailing list with over 500 entries which I need help with. My list is currently configured like this:

---------------------
name@email.com
firstname

name2@email2.com
firstname2
---------------------

I first need to check for duplicate email addresses in the file, so I would like to know if its possible to remove all of the "first names" from the file and all spaces so the end result looks like this:

---------------------
name@email.com
name2@email2.com
---------------------

The second thing I need to figure out is to add quotes around each item and add a comma between them, so it ends up like this:

------------------------------------
"name@email.com","firstname"
"name2@email2.com","firstname2"
------------------------------------

Thanks!
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Do the ------------------------------- lines really exist, or are they shown here for some type of clarity?

Do you have this?
---------------------
name@email.com
firstname

name2@email2.com
firstname2
---------------------
name3@email3.com
firstname3

name4@email4.com
firstname4
---------------------
or this?
name@email.com
firstname

name2@email2.com
firstname2

name3@email3.com
firstname3

name4@email4.com
firstname4
Hope this was helpful.............good luck,
Bob
bad959fl
Posts: 21
Joined: Wed Jun 15, 2005 11:32 pm

Post by bad959fl »

The file looks like this:

Code: Select all

name@email.com 
firstname 

name2@email2.com 
firstname2 

name3@email.com 
firstname3 

name4@email2.com 
firstname4
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

If the "first name" lines can be identified as those not containing an '@', then to remove them:
Find what: ^[^@]+\n
Replace with:

[X] Regular expression
To remove the blank lines:
Find what: \n\n
Replace with: \n

[X] Regular expression
If all "first name" lines are followed by exactly one blank line, then to remove the "first name" and blank lines together:
Find what: ^[^@]+\n\n
Replace with:

[X] Regular expression
bad959fl
Posts: 21
Joined: Wed Jun 15, 2005 11:32 pm

Post by bad959fl »

ben_josephs-

Awesome! Works perfectly. My last concern is how to setup the file, so the end result looks like this:

Before:

Code: Select all

email1@email1.com
firstname

email2@email2.com
firstname

email3@email3.com
firstname

After:

Code: Select all

"email1@email1.com","firstname"
"email2@email2.com","firstname"
"email3@email3.com","firstname"
Thanks for your help!
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Find what: ^([^@]+@.+)\n([^@]+)\n
Replace with: "\1","\2"

[X] Regular expression
This assumes you are using POSIX regular expression syntax:
Configuration | Preferences | Editor

[X] Use POSIX regular expression syntax
bad959fl
Posts: 21
Joined: Wed Jun 15, 2005 11:32 pm

Post by bad959fl »

ben_josephs-

Perfect! You saved me a ton of time.

However, I just ran into a small issue. I have have my list of email addresses and when I sort them for duplicates, I can't see which emails are being removed in TextPad. So, I take the file and run it in SSH with this Unix command:

Code: Select all

uniq -d "filename"
This shows me all the duplicate entries but what I noticed was its case sensitive, so it did not find a few entries which were entered as:

Code: Select all

email1@email.com
Email1@Email.COM
Is there any way to have find out which duplicate entries are removed when I run a "sort" in TextPad?

Thanks!
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

There isn't a way that I am aware of in TextPad to find this out.

Use

Code: Select all

uniq -d -i "filename" 
bad959fl
Posts: 21
Joined: Wed Jun 15, 2005 11:32 pm

Post by bad959fl »

ben_josephs-

Great, thanks for all your help! I really appreciate it.
bad959fl
Posts: 21
Joined: Wed Jun 15, 2005 11:32 pm

Post by bad959fl »

ben_josephs-

Thanks for all your help on the past questions. I have two more quick questions for you. I need to figure out a way to take entries on my newsletter list like this:

Code: Select all

email@email.com,John
email2@email2.com,Mike
email3@email3.com,Steve
The end result willl remove the first names and the commas with an end result looking like this:

Code: Select all

email@email.com
email2@email2.com
email3@email3.com
I also need to take existing entries like this:

Code: Select all

email@email.com,John
email2@email2.com,Mike
email3@email3.com,Steve
And have them end up like this:

Code: Select all

"email@email.com","John"
"email2@email2.com","Mike"
"email3@email3.com","Steve"
Thanks!
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Find what: ,.*
Replace with:

[X] Regular expression
Find what: ([^,]+),(.*)
Replace with: "\1","\2"

[X] Regular expression
These assume you are using POSIX regular expression syntax:
Configuration | Preferences | Editor

[X] Use POSIX regular expression syntax
Perhaps it's time to look up "Regular Expressions" in TextPad's help, and even, maybe, to glance at Jeffrey E. F. Friedl's much-recommended book Mastering Regular Expressions (http://www.oreilly.com/catalog/regex2/).
bad959fl
Posts: 21
Joined: Wed Jun 15, 2005 11:32 pm

Post by bad959fl »

ben_josephs-

Pefect. Thanks again for all your help.
Post Reply