Jump to content
TNG Community
Jan Suhr

Cleaning up Gedcom PLAC tag

Recommended Posts

Jan Suhr

In the Gedcom I get from MacFamilyTree I get a few "empty" commas if an address field is empty. Like ,,Colorado,USA. Another thing is that I want to have a space after each Comma in the address line when it is in TNG. I think that it looks better that way.
I have edit this manually with Search and Replace in a text editor but it takes some time and I thought I could make a script that just do it without any manual effort.

So I came up with this simple Node.JS javascript.

You can run it in VS Code terminal or in just the Terminal. You have to install NPM to run it and also add two Node.JS modules as per the require() at the top of the scriipt.
Only thing you have to do is set the path to the input and output files and then always save your Gedcom with the chosen input name.

It is for use as is and no support is offered. If you have some knowledge of JavaScript and Node.JS you will have no problem.  For others it is very simple to use, just Google run node.js scripts.

It processes my Gedcom with over 15000 persons in less than a second.

You might need to run the script more than one time to get everything cleaned up. Just rename the just output file to the name of the input and run again.

Note that you have to change the paths to suit your environment, it will work on Macs too.


const fs =  require("fs");
const readline = require("readline");

let myPath = "C:\\Users\\jansu\\Desktop\\myGedcom.ged";
async function processLineByLine(){
	const fileStream = fs.createReadStream(myPath);
	const rl = readline.createInterface({
		input: fileStream,
		crlfDelay: Infinity

	//let lineNumber = 0;

	let matchPlace = new RegExp(/(PLAC\s)/);
	//let repl1 = new RegExp(/(,,)/);
	let repl2 = new RegExp(/(PLAC\s,)/);
	//let repl3 = new RegExp(/,\\n/);
	//let repl4 = new RegExp(/,/);
	//let repl5 = new RegExp(/,\s{2}/);

	let newContent = "";
	let newLine = "";
	for await (const line of rl) {
		if (line.match(matchPlace) !== null){
			if (line.match(/(PLAC ,,,)/) !== null){
 				newLine = line.replace(",,,", "");
			else if (line.match(/(PLAC ,,)/) !== null){
				newLine = line.replace(",,", "");
			else if (line.match(repl2) !== null){
				newLine = line.replace(repl2, "PLAC ");
			else if (line.match(/(,,,)/) !== null){
				newLine = line.replace(",,,", ",");
			else if (line.match(/(,,)/) !== null){
				newLine = line.replace(",,", ",");
			else if (line.match(/(,)/) !== null){
				newLine = line.replace(/(,)(?!\s)/g, ", ");
				newLine = line; 
			newLine = line; 
		newContent = newContent + newLine + "\n";
	fs.writeFileSync("C:\\Users\\jansu\\Desktop\\export_clean.ged", newContent);


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now