Page 1 of 1
Searching and replacing a string
Posted: Mon Mar 15, 2010 3:17 pm
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?
Posted: Mon Mar 15, 2010 5:29 pm
by ben_josephs
Please put text examples in a
[/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
Posted: Mon Mar 15, 2010 5:56 pm
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
Posted: Mon Mar 15, 2010 8:11 pm
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.
Posted: Mon Mar 15, 2010 9:37 pm
by coledata
Thank you so much, I did manage to make that work.
How would I pare this into two fields:
Posted: Mon Mar 15, 2010 10:17 pm
by ben_josephs
Please explain precisely what input you want to produce what output.
Posted: Tue Mar 16, 2010 3:51 am
by coledata
I am so sorry about the delay in in responding:
I believe is what I need is:
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.
Posted: Tue Mar 16, 2010 7:14 am
by ben_josephs
What is the input that gives rise to that output?
Posted: Tue Mar 16, 2010 8:13 am
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;
Posted: Thu Mar 18, 2010 1:42 am
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