Search/Replace Duplicate Lines - Regular Expression Help

Find, replace, find in files, replace in files, regular expressions

Search/Replace Duplicate Lines - Regular Expression Help

Postby wbanik » Sun Jun 10, 2007 11:34 pm

Hello all,

I have delved into the UltraEdit help files and this forum trying to find a solution to my problem. I have a log that documents the x, y, and z coordinates of an event. The event is run 12 consecutive times. 11 entries in the log contain pre-planned (theoretical/ideal) coordinates and a 12th entry contains the actual coordinates where all 12 events occurred. I need to replace (delete) the 11 theoretical event entries. I saw in a similar thread Removing lines with partial duplicate content with spaces.

a solution for doing this but I don't understand how to employ the regular expressions (I'm not a programmer) in my application. I am using UEStudio version 6.20A+2. Below is a sample of an event log I am working on:

Code: Select all
Line               Point       X Value     Y Value       Z Value     JD&Time

S1132.0            5132.01V1     0.0   0 0 0.01705678.4  703551.5 537.7134073317
S1132.0            5132.01V1     0.0   0 0 0.01705678.4  703551.5 537.7134073329
S1132.0            5132.01V1     0.0   0 0 0.01705678.4  703551.5 537.7134073342
S1132.0            5132.01V1     0.0   0 0 0.01705678.4  703551.5 537.7134073354
S1132.0            5132.01V1     0.0   0 0 0.01705678.4  703551.5 537.7134073406
S1132.0            5132.01V1     0.0   0 0 0.01705678.4  703551.5 537.7134073419
S1132.0            5132.01V1     0.0   0 0 0.01705678.4  703551.5 537.7134073431
S1132.0            5132.01V1     0.0   0 0 0.01705678.4  703551.5 537.7134073444
S1132.0            5132.01V1     0.0   0 0 0.01705678.4  703551.5 537.7134073456
S1132.0            5132.01V1     0.0   0 0 0.01705678.4  703551.5 537.7134073508
S1132.0            5132.01V1     0.0   0 0 0.01705678.4  703551.5 537.7134073521
S1132.0            5132.01V1     0.0   0 0 0.01705683.9  703551.9 537.7134073533
S1420.0            5137.01V1     0.0   0 0 0.01719908.8  710179.6 470.6134073821
S1420.0            5137.01V1     0.0   0 0 0.01719899.0  710181.7 470.6134073605
S1420.0            5137.01V1     0.0   0 0 0.01719899.0  710181.7 470.6134073618
S1420.0            5137.01V1     0.0   0 0 0.01719899.0  710181.7 470.6134073630
S1420.0            5137.01V1     0.0   0 0 0.01719899.0  710181.7 470.6134073643
S1420.0            5137.01V1     0.0   0 0 0.01719899.0  710181.7 470.6134073655
S1420.0            5137.01V1     0.0   0 0 0.01719899.0  710181.7 470.6134073707
S1420.0            5137.01V1     0.0   0 0 0.01719899.0  710181.7 470.6134073720
S1420.0            5137.01V1     0.0   0 0 0.01719899.0  710181.7 470.6134073732
S1420.0            5137.01V1     0.0   0 0 0.01719899.0  710181.7 470.6134073744
S1420.0            5137.01V1     0.0   0 0 0.01719899.0  710181.7 470.6134073757
S1420.0            5137.01V1     0.0   0 0 0.01719899.0  710181.7 470.6134073809

From the example above you can see the line, point, x, y, and z values are the same for 11 of the 12 recorded events and the 12th contains the actual positioning. The Julian Date and time stamp increments and is not identical.

Can someone please help me with the regular expressions to search and replace these duplicate entries.

Best regards,

William
User avatar
wbanik
Newbie
 
Posts: 2
Joined: Sat Jun 09, 2007 11:00 pm

Re: Search/Replace Duplicate Lines - Regular Expression Help

Postby pietzcker » Mon Jun 11, 2007 5:46 am

Hi,

can you try if this Perl regex works for you? (If you haven't done so yet, activate Perl regular expressions in the options dialog first)

Search string:
Code: Select all
(?:(?:^((?:[^\s]+ +){5})).*?\r\n){11}(\1.*?)$

Replace string
Code: Select all
\2

It assumes that there is the same number of spaces at each location in a 12-line block. If that's not the case, I'd run a replace multiple spaces by one space first, regex for that would be

Code: Select all
 {2,}

(note the leading space), replace with " ".

One caveat: If you don't always have 12 consecutive lines that belong together, the regex might mismatch. If that may be the case, the regex will need to be changed.

Best regards,
Tim
User avatar
pietzcker
Master
Master
 
Posts: 241
Joined: Sun Aug 22, 2004 11:00 pm

Re: Search/Replace Duplicate Lines - Regular Expression Help

Postby wbanik » Mon Jun 11, 2007 6:24 pm

Tim,

thanks for the input. The Perl regular expression as posted worked.

Best regards,

William
User avatar
wbanik
Newbie
 
Posts: 2
Joined: Sat Jun 09, 2007 11:00 pm


Return to Find/Replace/Regular Expressions