Searching and replacing a string

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
coledata
Posts: 5
Joined: Mon Mar 15, 2010 2:24 pm
Location: USA

Searching and replacing a string

Post by coledata »

I am trying to parse a large txt file produced from a PDF.

Unfortunately the PDS 'save as text' system was inconsitent.

Within the file there are strings of random numbers, like:
0 0 0 0 5,107 0 0 -5,107
0 0 0 0 5,277 0 0 -5,277

As you can see, the second row is double spaced which would allow me to insert a field delimiter.

Therefore I need to find a way to find and replace the first sample entering an extra space to make them all consistent.

Does anyone have any ideas?
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Please put text examples in a

Code: Select all

[/color][/b]...[b][color=blue]
[/color][/b] block, so that we don't have to examine the source of the page to see what your examples really look like.

Does this do what you need?
[Replace the underscores with spaces]

Find what: ([0-9])_(-?)\<
Replace with: \1__\2

[X] Regular expression

Replace All
It assumes you are using Posix regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
coledata
Posts: 5
Joined: Mon Mar 15, 2010 2:24 pm
Location: USA

Post by coledata »

No, unfortunately that doesn't get it; comes up with cannot find regular expression.

Unfortunately these numbers occur in the midle of a line:

NewRecord; AL 69230 FLEET GROUP PHPL2000097 05/01/08 05/01/09 PHAL08060333806 05/18/08 0 0 0 0 0 0 0 0 Catastrophe: Claim Status: OP

NewRecord; AL AP 69230 FLEET GROUP PHPL2000097 05/01/08 05/01/09 PHAL08050325088 Hernandez, S 05/11/08 0 0 0 0 502 0 0 -502 Catastrophe: Claim Status: CL
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Please use

Code: Select all

[/color][/b] blocks for your examples (preferably ones with shorter lines), like this:
[code]NewRecord;  AL  69230  FLEET GROUP  PHPL2000097  05/01/08 05/01/09 PHAL08060333806  05/18/08  0  0  0  0  0  0  0  0  Catastrophe:  Claim Status:  OP
NewRecord;  AL  AP  69230  FLEET GROUP  PHPL2000097  05/01/08 05/01/09 PHAL08050325088 Hernandez, S  05/11/08  0 0 0 0 502 0 0 -502  Catastrophe:  Claim Status:  CL</span><span class="gensmall"></span></td>
The regex I gave you most definitely does work on these examples. Make sure there isn't a space at the end of the regex. The replacement produces this:

Code: Select all

NewRecord;  AL  69230  FLEET GROUP  PHPL2000097  05/01/08  05/01/09  PHAL08060333806  05/18/08  0  0  0  0  0  0  0  0  Catastrophe:  Claim Status:  OP
NewRecord;  AL  AP  69230  FLEET GROUP  PHPL2000097  05/01/08  05/01/09  PHAL08050325088  Hernandez, S  05/11/08  0  0  0  0  502  0  0  -502  Catastrophe:  Claim Status:  CL</span><span class="gensmall"></span></td>
It has doubled each single space that follows a digit.
coledata
Posts: 5
Joined: Mon Mar 15, 2010 2:24 pm
Location: USA

Post by coledata »

Thank you so much, I did manage to make that work.

How would I pare this into two fields:

Code: Select all

Devenny, B 04/14/09
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Please explain precisely what input you want to produce what output.
coledata
Posts: 5
Joined: Mon Mar 15, 2010 2:24 pm
Location: USA

Post by coledata »

I am so sorry about the delay in in responding:

I believe is what I need is:

Code: Select all

Devenny, B; 04/14/09;
That is Name, Initial, Date, where name and initial are Xxxxx, X, and the date is a separate field. (Using ";" as the delimiter.)

I realy have to thank you for your generous assitance; I grew up in the days where fiels where 64 bits, and anrhing after that was deleted.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

What is the input that gives rise to that output?
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

I've made some guesses.

This will produce output similar to what you have described from records similar to the ones above, with an empty name field if there is no name:
Find what: ^[^,]* ([^ ]*, [a-z]|) +([0-9]{2}/[0-9]{2}/[0-9]{2}).*
Replace with: \1; \2;
coledata
Posts: 5
Joined: Mon Mar 15, 2010 2:24 pm
Location: USA

Post by coledata »

Thank you Ben, I seriously appreciate your help.

Unfortunately there are about 10,000 lines in this text, it seems 80 percent of it is cruft.

I have now abandoned the project for a couple of reasons:
1: The data input is crap
2: The insurance company behind this don't seem to care, although it seriously affects their profitability.

I am extremely grateful for your input, and really admire your skills in this field.

Again, thank you
John
Post Reply