Page 1 of 1

Need Help Adjusting Lines

Posted: Tue Jun 28, 2005 2:48 am
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!

Posted: Tue Jun 28, 2005 3:00 am
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

Posted: Tue Jun 28, 2005 3:01 am
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

Posted: Tue Jun 28, 2005 10:02 am
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

Posted: Tue Jun 28, 2005 1:30 pm
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!

Posted: Tue Jun 28, 2005 1:48 pm
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

Posted: Tue Jun 28, 2005 2:09 pm
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!

Posted: Tue Jun 28, 2005 2:28 pm
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" 

Posted: Tue Jun 28, 2005 2:35 pm
by bad959fl
ben_josephs-

Great, thanks for all your help! I really appreciate it.

Posted: Thu Jul 14, 2005 10:32 pm
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!

Posted: Thu Jul 14, 2005 11:09 pm
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/).

Posted: Sat Jul 16, 2005 7:09 pm
by bad959fl
ben_josephs-

Pefect. Thanks again for all your help.