0

i'm having troubles splitting a .txt file that i exported from a db.

The file contains longitude and latitude coordinates where each entrie has the following structure:

5d11'25.753"W   39d1'29.733"N 0.000

I need to split this file into two separate files, one that contains the longitude and other the latitude. I don't need the 0.000 in the records.

Any idea on how i can do this, the file is quite long and i can't do it manually.

Cláudio Ribeiro
  • 1,509
  • 3
  • 37
  • 65
  • What OS are you splitting the file on? What scripting languages do you have access to? How big is 'quite long'? Under Unix you could look at using 'cut'. Under windows if 'quite long' isn't too long you could even use Excel to split the columns... – forsvarir May 24 '12 at 11:09
  • I'm using windows, but i don't have access to excel. – Cláudio Ribeiro May 24 '12 at 11:11
  • Do you have access to any scripting languages? Would it be easier to just rerun your export twice and only export one of the columns with each run? This might be a good starting point: http://stackoverflow.com/a/1564614/592182 – forsvarir May 24 '12 at 11:13
  • I tried that, but i'm already converting the data to (long,lat) because the original is in a very old location format. The software i'm using to convert that data only allows me to convert into (long,lat) and i need the data to be in (lat,long) to be in concordance with the current DB. – Cláudio Ribeiro May 24 '12 at 11:16
  • Also, i have access to vsbs... But i need help with the script, as i never used it before. – Cláudio Ribeiro May 24 '12 at 11:22
  • I've posted an example batch file that seems to work... – forsvarir May 24 '12 at 11:29

1 Answers1

1

For a given input file 'input.txt', this should create two outputs ('long.txt' and 'lat.txt') with the appropriate columns. Note, if you run it again, you'll need to delete 'long.txt' and 'lat.txt', or the columns will simply be appended to the existing file.

for /f "tokens=1,2,3 delims= " %%i in (input.txt) do (
    echo %%i >> long.txt
    echo %%j >> lat.txt
)

Based on this answer.

Just copy the code into a batch file (extract.bat) and run...

Community
  • 1
  • 1
forsvarir
  • 10,749
  • 6
  • 46
  • 77
  • The script worked, it removed the 0.000 from on file and placed in a different file. I wanted to separate the longitude from the latitude. How can i change the script to perform that separation? (i want the delim to be a tab) – Cláudio Ribeiro May 24 '12 at 11:36
  • 1
    @CláudioRibeiro: after `delims=`, put a tab instead of a space before the `"` – forsvarir May 24 '12 at 11:39
  • Thanks a lot, after looking to the code i realised it was that. – Cláudio Ribeiro May 24 '12 at 11:40