Long batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pditty8811
Posts: 184
Joined: 21 Feb 2013 15:54

Long batch file

#1 Post by pditty8811 » 05 Mar 2013 00:49

Read file, then enter number into perl script then run perl

I would like a batch that reads a file called ships.txt, then takes the entries (each on a line) from that file and compares them to a file with the file extension of *.map (say test.map), looking for the match, which will always be at the end of a line. Then take those coordinates (they will be a pair of numbers that are actually long. and lat. in meters) and plug those coordinates into a perl script, which produces a file. I'd like then to read the file that is produced by the perl script and delete an entry that is found within another file using information from the perl script by-product.

Lets start from scratch. One step at a time
Step 1:

1. I would like a batch that compares "test.map" and "ships.txt". If it finds a match, and the match will always be at the end of a line in test.map, I'd like it to grab map coordinates.

This is what test.map will look like:

Code: Select all

Pt0=14497903.00,-813490.00,0.00,Mark 1
Pt1=14417253.00,-812258.00,0.00,Mark 2
Pt2=15442253.00,-112258.00,0.00,Mark 3
etc...


ships.txt will look something like this:

Code: Select all

Mark 1
Mark 3
Mark 4
etc...



So I'd like the batch to read ships.txt and be looking for the entry "Mark 1" or "Mark 2" etc..., and if it is found in test.map, to grab the coordinates just before the ",0.00,Mark #" Notice the coordinates have two decimal places and they can also be negative.

After we assign those coordinates variables, we can move onto Step 2. But one step at a time so not to intimidate anyone trying to help me do this.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Long batch file

#2 Post by foxidrive » 05 Mar 2013 04:23

Are you doing this multiple times for a ships.txt file or only for the first entry in the file?


Will the batch file have to run multiple times, at the same time?

pditty8811
Posts: 184
Joined: 21 Feb 2013 15:54

Re: Long batch file

#3 Post by pditty8811 » 05 Mar 2013 13:44

It will be run multiple times, to compare all entries in ships.txt with test.map.

The batch file will not have to run multiple times, if there is a loop to check for all entries. If it can check for all entries in ships.txt then it only has to run once.

pditty8811
Posts: 184
Joined: 21 Feb 2013 15:54

Re: Long batch file

#4 Post by pditty8811 » 05 Mar 2013 13:52

bTW your last code is working flawlessly by the way.

Aacini
Expert
Posts: 1932
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Long batch file

#5 Post by Aacini » 05 Mar 2013 19:50

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem Read file, then enter number into perl script then run perl


rem I would like a batch that reads a file called ships.txt, then takes the entries (each on a line) from that file
for /F "delims=" %%a in (ships.txt) do (

   rem and compares them to a file with the file extension of *.map (say test.map).
   for /F "tokens=1,2 delims=," %%b in ('findstr "%%a" test.map') do (
      rem Then take those coordinates (they will be a pair of numbers that are actually long. and lat. in meters)   
      set %%b,%%c
   )
)

REM At this point, matching "Pt" array elements have the coordinates in this form:
REM Pt0=14497903.00,-813490.00
REM Pt1=14417253.00,-812258.00
REM Pt2=15442253.00,-112258.00
REM etc...

rem and plug those coordinates into a perl script, which produces a file.

REM For example, if you want to collect all "Pt" elemens in one string called Coords
REM enclosing each coordinate pair in parentheses:
set Coords=
for /F "tokens=2 delims==" %%a in ('set Pt') do (
   set "Coords=!Coords!(%%a)"
)

REM This way, you may run your perl script and plug the coordinates into it:
perl yourScript.prl %Coords% > theFile.txt


Antonio

Post Reply