I'm stumped on where to begin on this macro.....

General questions about using TextPad

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

Post Reply
grindy
Posts: 20
Joined: Mon Aug 29, 2005 6:10 pm

I'm stumped on where to begin on this macro.....

Post by grindy »

I have long text files (sample below) - where each line has some numeric data that I would like to strip everything else from.

What you see below is a sample of one of the text files. You'll notice that each line has a value for damage - and that value always precedes the text "points of damage".
[6/14/2015 4:30:05 PM] Elder Wolf takes 16 points of damage from Luka Melehan's Glacial Glissade.
[6/14/2015 4:32:27 PM] Ebon Cultist Champion takes 16 points of damage from Luka Melehan's Glacial Glissade.
[6/14/2015 4:33:30 PM] Large Grizzly Bear takes 15 points of damage from Luka Melehan's Glacial Glissade.
[6/14/2015 4:33:41 PM] Grizzly Bear takes 3 points of damage from Robert Frost's Glacial Glissade.
[6/14/2015 4:33:41 PM] Grizzly Bear has been slain by Robert Frost's Glacial Glissade!
[6/14/2015 4:33:56 PM] Ebon Cultist Champion takes 7 points of damage from Robert Frost's Glacial Glissade.
[6/14/2015 4:35:24 PM] Ebon Cultist Champion takes 34 points of damage from Robert Frost's Glacial Glissade.
[6/14/2015 4:35:37 PM] Ebon Cultist Champion takes 1 point of damage from Luka Melehan's Glacial Glissade.
[6/14/2015 4:35:37 PM] Ebon Cultist Champion takes 1 point of damage from Robert Frost's Glacial Glissade.
[6/14/2015 4:35:45 PM] Ebon Cultist Champion takes 5 points of damage from Luka Melehan's Glacial Glissade.
[6/14/2015 4:36:34 PM] Ebon Cultist Champion takes 31 points of damage from Luka Melehan's Glacial Glissade.
[6/14/2015 4:37:06 PM] Ebon Cultist Champion takes 4 points of damage from Luka Melehan's Glacial Glissade.
[6/14/2015 4:37:36 PM] Ebon Cultist Champion takes 7 points of damage from Luka Melehan's Glacial Glissade.
What I want to do is - keep the numeric value that always precedes that "points of damage" phrase - and cut out EVERYTHING else in each line - leaving just the numeric value (that never excedes 3 digits), and end up with the file looking like this: (based on the sample above).

16
16
15
3
7
34
1
1
5
31
4
7

If a line does NOT contain that phrase (as in line 5 in the sample), then that entire line should be deleted as well, but I can certainly live with just ignoring that line, if it's unduly cumbersome....

If anyone would be so kind as to assist me here, I'd appreciate it greatly!

Thanks in advance,
grindy
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Re: I'm stumped on where to begin on this macro.....

Post by ben_josephs »

grindy wrote:that value always precedes the text "points of damage"
... or "point of damage".

Using Search | Replace... (<F8>) you can do it in two steps:
Find what: .* (\d+) points? of damage .*
Replace with: $1

[X] Regular expression

Replace All
then
Find what: ^(?!\d+).*\n
Replace with: [nothing]

[X] Regular expression

Replace All
or, using conditional expressions, in one step:
Find what: (?:^.* (\d+) points? of damage .*)|^.+\n
Replace with: ?1($1):?2()

[X] Regular expression

Replace All
grindy
Posts: 20
Joined: Mon Aug 29, 2005 6:10 pm

Post by grindy »

ben-josephs - you're a dang macro genius....

I wish I understood what each of those macro characters mean. I know what * means, but that's about the extent...

Anyway, it works really fine........

So, once again, thank you for taking the time to write the macro for me.
:)
Post Reply