-1

I thought I could do this, but this is just not my profession. Below, I am trying to take the second column of data and produce a .txt (.csv) which separates the second column into two columns. There is a comma present in the data but it is surrounded by double quotes.

I am getting a .txt file that reads

SourceFile,GPSPosition
Picture1.jpg,"21 deg 14' 4.621"" S, 159 deg 46' 45.358"" W"
Picture2.jpg,"21 deg 14' 4.621"" S, 159 deg 47' 45.358"" W"
Picture3.jpg,"21 deg 14' 4.621"" S, 159 deg 48' 45.358"" W"

Note: The GPS position is recognised as one cell in .csv looking like "21 deg 14' 4.621"" S, 159 deg 48' 45.358"" W"

I figured I would create two .txt files, One for easting (W) and one for Northing (S) and merge them afterwards.

@echo off
set batdir=%~dp0
pushd "%batdir%"

FOR /F "usebackq tokens=2 delims=," %%A IN ("%~dp0\filename") DO @echo %%A > "%~dp0\output.csv"
Call Easting.bat

I have a second .bat file (Easting.bat) which has Tokens=3. The Results of these two documents are:

"21 deg 14' 4.621"" s and 159 deg 48' 45.358"" W"

  • What command do I use to grab all of the Northing and Easting GPS points in separate rows?
  • How do I merge the two files together with as comma-separated values?
  • Thank you for the question. The simple answer is that it didn't work as I intended, but instead of saying "it didn't work", I'm trying to see where the problem lies so we can work through the issue. – SlowlyMakingThingsHappen Feb 12 '21 at 00:13

1 Answers1

0

Based upon only your provided example file content, and the code you used yourself, here's an example which should just split the second field at the comma, and output the results to a new file. I have deliberately ignored the header, as you'd need to add an additional field to that too, and probably rename the second.

@Echo Off
SetLocal EnableExtensions
PushD %~dp0
Set "input=filename"
Set "output=output.csv"
If Not Exist "%input%" GoTo :EOF
(For /F "UseBackQ Tokens=1,* EOL=, Delims=," %%G In ("%input%"
) Do For /F "Tokens=1,* EOL=, Delims=," %%I In ("%%~H") Do (
    For /F "Tokens=*" %%K In ("%%J") Do Echo %%G,"%%I","%%K")
) 1> "%output%"

Expected output:

Picture1.jpg,"21 deg 14' 4.621"" S","159 deg 46' 45.358"" W"
Picture2.jpg,"21 deg 14' 4.621"" S","159 deg 47' 45.358"" W"
Picture3.jpg,"21 deg 14' 4.621"" S","159 deg 48' 45.358"" W"
Compo
  • 36,585
  • 5
  • 27
  • 39