Delete each line with less than 4 words and...

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
beric
Posts: 3
Joined: Mon May 02, 2011 10:59 am

Delete each line with less than 4 words and...

Post by beric »

I need to delete every line that contains less than 4 words or more than 10.
What can I do?
User avatar
SteveH
Posts: 327
Joined: Thu Apr 03, 2003 11:37 am
Location: Edinburgh, Scotland
Contact:

Post by SteveH »

Can you provide some more information on the sort of text you want to search? Is this structured data or English prose? Is it punctuated in some way?

If this is prose rather than data then words can be separated by spaces, commas, semi colon, question marks etc.

Please post an example.
Running TextPad 5.4 on Windows XP SP3 and on OS X 10.7 under VMWare or Crossover.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Use "Posix" regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
Remove lines that contain fewer than 4 words:
Find what: ^(\<[a-z0-9_']+\>[^a-z0-9_']*){1,3}\n
Replace with: [nothing]

[X] Regular expression

Replace All
Remove lines that contain more than 10 words:
Find what: ^(\<[a-z0-9_']+\>[^a-z0-9_']*){11,}\n
Replace with: [nothing]

[X] Regular expression

Replace All
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

These are more accurate:

Remove lines that contain fewer than 4 words:
Find what: ^[^a-z0-9_']*([a-z0-9_']+[^a-z0-9_']+){0,2}[a-z0-9_']+[^a-z0-9_']*\n
Replace with: [nothing]

[X] Regular expression

Replace All
Remove lines that contain more than 10 words:
Find what: ^[^a-z0-9_']*([a-z0-9_']+[^a-z0-9_']+){10,}[a-z0-9_']+[^a-z0-9_']*\n
Replace with: [nothing]

[X] Regular expression

Replace All
beric
Posts: 3
Joined: Mon May 02, 2011 10:59 am

Post by beric »

Great thanks!
actroid
Posts: 9
Joined: Sun Feb 27, 2011 1:27 pm

Post by actroid »

Thanks i follow your instruction and work well....
Have file like this:

mybuyeremail@email.com:mybuyeraddress
mybuyeremail3@email.com:
mybuyeremail4@email.com:
mybuyeremail1@email.com:mybuyeraddress1


how to delete all line donot contain mybuyeraddress....

TQ
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Search | Find... (<F5>):
Find what: mybuyeraddress

Mark All
<Esc>
Search | Invert All Bookmarks
Edit | Delete | Bookmarked Lines
Post Reply