Comma, tab or semicolon? Find the delimiter in a survey TXT file
Use a two-record test to identify the separator in a field export and produce a comma-delimited delivery without changing punctuation in descriptions.
107;1502.300;7330.150;28.61;Top of kerb, drivewayOn this page
Count fields with a known descriptionDistinguish tabs from aligned spacesRead the delivered textRecognize a mixed exportA file named points.txt could contain tabs, commas, semicolons or padded columns. The extension tells you almost nothing about what separates the values. The fastest way to find out is to take a record whose point name and description you recognize, then predict the five values a parser should give back.
Consider these two lines from an illustrative kerb survey:
107;1502.300;7330.150;28.61;Top of kerb, driveway
108;1504.100;7332.550;28.65;Top of kerb, return
Count fields with a known description
The first feature is a single point with the description “Top of kerb, driveway.” Its description includes a comma. Four semicolons divide the record into five fields. Reading the same line as comma-delimited yields two fields, the first containing virtually the whole record. That observation makes semicolon the candidate to test.
In the formatter, choose semicolon, set the input order to PNEZD and inspect the first row. The northing should be 1502.300 and the easting 7330.150. Try the second row too. From point 107 to 108 the coordinates change by +1.800 north and +2.400 east. The horizontal distance should therefore be 3.000 in job units. That small geometric check catches a damaged numeric field that a five-column count alone would miss.
Distinguish tabs from aligned spaces
A tab-delimited file can look like a little printed table in a text editor. Turn on visible whitespace or put the caret before the northing and step left by one character. A tab may move the caret several screen positions. Spaces in the description remain ordinary spaces. Replacing every run of whitespace with a comma would split “Top of kerb” into three fields.
If the source is a fixed-width report, get its column specification or ask the collector for a delimited export. A negative coordinate, a longer name or an extra decimal place may cross the visual position you thought was a column boundary. Parse fixed widths by their defined offsets. Check one long identifier and one negative value before accepting the result.
Read the delivered text
Keep the output in PNEZD order for this test. The downloaded CSV should represent point 107 like this:
107,1502.300,7330.150,28.61,"Top of kerb, driveway"
The surrounding quotation marks allow the description to contain a literal comma. Open the output with a CSV-aware reader and expect the description value without the surrounding marks. A raw count of commas now gives five commas for five fields. Four commas divide the fields and the fifth belongs to the description. This explains why simple find-and-replace is unreliable even when the first test row looks easy.
Recognize a mixed export
A job assembled from several crews can have a semicolon section followed by tab-delimited data. Inspect the first and last records and the rows at any crew or date change. A sudden run of single-field records is evidence of a different format, not a reason to change the separator midway through an import dialog. Split at the documented change, convert each homogeneous part and reconcile the identifier lists before merging.
Tell the recipient the input separator, the output separator, the field order and the number of accepted records. One sentence about the example prevents a familiar mistake: the delivered file is comma-delimited, even though the collector wrote semicolons. A test import using the old setting can make a perfectly good delivery look like another broken export.
For an unknown export, save a tiny fixture containing the two records above beside your conversion settings. Ask a colleague to parse it using those settings and report back the point count, the first description and the northing of 108. A correct response is two points, “Top of kerb, driveway” and 1504.100. This takes less time than diagnosing a delimiter mismatch after a full site import.