0

(very new to coding in general. Starting with BATCH file.)

I have the following main file I use for some aviation data:

Documents\DATA\LIVE\sector.txt

[AIRPORT]
UT12 (coordinates)
U42 (coordinates)
SLC (coordinates)
;APTEND

[VOR]
BIL (coordinates)
TCH (coordinates)
VEL (coordinates)
;VOREND

Every so often, there are updates to this data and those updates are stored in individual text files like so:

Documents\DATA\PREVIEW\AIRPORT.txt

[AIRPORT]
BZN (coordinates)
6S8 (coordinates)
GTF (coordinates)

and...

Documents\DATA\PREVIEW\VOR.txt

[VOR]
LWT (coordinates)
TCH (coordinates)
DTA (coordinates)

I am trying to figure out how to create a batch file that would search sector.txt for the different strings of data [AIRPORT} to ;APTEND and then replace the contents with the contents of the file in the Preview folder.

The category heads [AIRPORT] and [VOR] never change but the data below it does including the number of lines of data, and that is where I am stuck.

The following code won't work because it is not a single line or element that I am looking to replace, but rather a group of data that changes all the time.

powershell -Command "(gc myFile.txt) -replace 'foo', 'bar' | Out-File myFile.txt"

Points in the right direction would be appreciated! Thanks!

KSanders
  • 3
  • 4
  • you need to use `FOR /F` and [disable eol](https://stackoverflow.com/questions/32192678/how-to-disable-both-eol-and-delims-options-of-for-f) or `SET /P` – ScriptKidd Apr 26 '20 at 02:11
  • I would suggest the most useful way would be to parse `LIVE\sector.txt` splitting it into individual files, with names based on the section, and each containing the lines for that section. Then you could copy your `PREVIEW\*.txt` files overwriting any you've just split, before recreating `LIVE\sector.txt` with all of the individual files using `Copy` or `Type`. The resulting `LIVE\sector.txt` should then contain its original information, but with replaced sections where new files were copied. _(I assume that the order of the labelled sections and the semicolon commented lines are irrelevant.)_ – Compo Apr 28 '20 at 04:01

0 Answers0