elliotchance / gedcom

👪 A Go library and CLI tools for encoding, decoding, traversing, merging, comparing, querying and publishing GEDCOM files.
MIT License
94 stars 20 forks source link

Merging Individuals Within Same Gedcom #320

Open twcardenas opened 2 years ago

twcardenas commented 2 years ago

Is there currently a cli command that can merge two individual nodes within the same Gedcom file and output it to a new file?

elliotchance commented 2 years ago

In theory, it might be possible to filter the same file twice and merge and output to GEDCOM, but I seriously doubt this would work. Something like:

gedcomq -gedcom file.ged -gedcom file.ged -format gedcom \
  'Bob is Document1 | .Individuals | Only(.Name = "Bob Smith"); Robert is Document2 | .Individuals | Only(.Name = "Robert Smith"); MergeDocumentsAndIndividuals(Bob, Robert)' > merged.ged

I suspect even if this does not error, it won't be able to convert Bob/Robert to valid Documents for the merge.

Your best bet is to write this in go (or, if you're feeling ambitious, update the query language to accordingly)

twcardenas commented 2 years ago

I'll take a look at giving that a go and updating it to do that.

When I started to query for a specific person using the Pointer

 .\gedcom query -gedcom file.ged '.Individuals | Only(.Pointer = "I2")'

The output was

2021/12/31 12:55:51 ERROR: no such variable I2

Does the search not work for this field?

twcardenas commented 2 years ago

I also tried

.\gedcom query -gedcom .\file.ged ' .Individuals | Only(.Identifier != "@I1@")'

And get

2021/12/31 13:11:30 ERROR: expected EOF but found (
elliotchance commented 2 years ago

On Mac, it seems to be working correctly:

elliot@Elliots-MBP bin % ./gedcom query -gedcom ancestry.ged '.Individuals | Only(.Pointer = "P323") | Length' 
1
elliot@Elliots-MBP bin % ./gedcom query -gedcom ancestry.ged '.Individuals | Only(.Pointer != "P323") | Length'
387

I just found on windows the terminal doesn't accept this syntax for double quotes: https://stackoverflow.com/questions/7760545/escape-double-quotes-in-parameter

I think you need to escape the double quotes:

 .\gedcom query -gedcom file.ged '.Individuals | Only(.Pointer = \"I2\")'

Or this?

 .\gedcom query -gedcom file.ged ".Individuals | Only(.Pointer = ""I2"")"