RootsWeb.com Mailing Lists
Total: 1/1
    1. Re: Search and replace in one field
    2. Charlie Hoffpauir
    3. On Tue, 19 Feb 2013 19:15:50 -0500, Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote: >On Tue, 19 Feb 2013 08:13:16 -0600, Charlie Hoffpauir ><invalid@invalid.com> declaimed the following in >soc.genealogy.computing: > > >> >> Not exactly. The duplication of names only occurs when the GEDCOM is >> imported into RM and then RM displays the name, as in a report. The >> presumption is that this is caused because Hugh surrounded some given >> names with Quote marks, doing so to indicate that these given names >> were what the person was commonly known by. >> >> So a portion of the GEDCOM might look like this: >> >> 0 @I1@ INDI >> 1 NAME Gerald "Bernard" /Landry/ >> 2 GIVN Gerald "Bernard" >> 2 SURN Landry >> 1 SEX M >> 1 BIRT >> 2 DATE 9 MAR 1937 >> 2 PLAC St-Jacques >> 0 @I2@ INDI >> 1 NAME Bernard /St-Jacques/ >> 2 GIVN Bernard >> 2 SURN St-Jacques >> 1 SEX M >> 1 FAMS @F1@ >> 1 FAMC @F2@ >> >> And we want to process it so that it looks like this: >> >> 0 @I1@ INDI >> 1 NAME Gerald ~Bernard~ /Landry/ >> 2 GIVN Gerald ~Bernard~ >> 2 SURN Landry >> 1 SEX M >> 1 BIRT >> 2 DATE 9 MAR 1937 >> 2 PLAC St-Jacques >> 0 @I2@ INDI >> 1 NAME Bernard /St-Jacques/ >> 2 GIVN Bernard >> 2 SURN St-Jacques >> 1 SEX M >> 1 FAMS @F1@ >> 1 FAMC @F2@ >> >> Where the tilde I used might be any other character of our choosisng >> as long as it were not a character that would also appear elsewhere in >> the Given name fields of the GEDCOM > > As before -- the "big" PowerShell command line is wrapping... > >PS E:\UserData\Wulfraed\My Documents> get-content e:\sample.ged > 0 @I1@ INDI > 1 NAME Gerald "Bernard" /Landry/ > 2 GIVN Gerald "Bernard" > 2 SURN Landry > 1 SEX M > 1 BIRT > 2 DATE 9 MAR 1937 > 2 PLAC St-Jacques > 0 @I2@ INDI > 1 NAME Bernard /St-Jacques/ > 2 GIVN Bernard > 2 SURN St-Jacques > 1 SEX M > 1 FAMS @F1@ > >PS E:\UserData\Wulfraed\My Documents> get-content e:\sample.ged | >foreach {$_ -replace '(.*) NAME (.*) "(.*)" (.*)', '$1 $2 ~$3~ $4' >-replace '(.*) GIVN (.*) "(.*)"', '$1 GIVN $2 ~$3~'} >e:\new.ged > >PS E:\UserData\Wulfraed\My Documents> get-content e:\new.ged > 0 @I1@ INDI > 1 Gerald ~Bernard~ /Landry/ > 2 GIVN Gerald ~Bernard~ > 2 SURN Landry > 1 SEX M > 1 BIRT > 2 DATE 9 MAR 1937 > 2 PLAC St-Jacques > 0 @I2@ INDI > 1 NAME Bernard /St-Jacques/ > 2 GIVN Bernard > 2 SURN St-Jacques > 1 SEX M > 1 FAMS @F1@ >PS E:\UserData\Wulfraed\My Documents> > > Which translates, roughly, to "read the source file, feeding the >lines, one at a time, to a loop (in which the current line is $_) >perform two replace operations; the first looking for NAME lines (at any >level), and the second looking for "GIVN" lines (also at any level), >sending the results of the lines to a new file. THAT is elegant! I will have to learn more about Powershell. I've downloaded several documents and the MS Powershell e-book powershell_selflearn.pdf. It all looks formidable, but then I only need (I think) the info on file handling and Regular Expressions to get started with handling text files like GEDCOMS. Thanks very much for the example.

    02/19/2013 12:28:28