0

PBX の電話長距離交換情報を含むテキスト ファイルがあります。入力ファイルには次が含まれます。

sourceNPA,srcNNX,DestinationNPA,destNNX
954,327,954,201
954,327,954,202
954,327,954,203
954,327,954,210 
954,327,954,212
954,327,954,213 
954,327,954,214 
etc...

会社のポリシー上の理由から (私がコーダーではないという理由だけでなく)、VBS または Windows バッチ以外は使用できません。これらを手動で行うことが期待されていますが、範囲に変換する必要があるのは 43000 以上です。

指定されたテキスト ファイルの各行を読み取る必要があります。dNPA と dNXX (各行の最後の 2 つの引数) が連続しているかどうかを確認し、連続している場合は範囲​​を決定して、入力リストが出力で次のように読み取られるようにします。

954,327,954,201,203
954,327,954,210,210
954,327,954,212,214
etc...

配列の使用法を調べて、一時ファイルに 1 行を読み取ろうとしましたが、これにはトリックが必要です。

私はいじくり回してきましたが、それを示すことはほとんどありません:

@echo off
setlocal enabledelayedexpansion
set lineNumber=1
if exist outputFile.txt del outputFile.txt

for /f "tokens=1-6 delims=,;" %%a in (inputFile.txt) do call :process %%a %%b %%c %%d
:EOF

:process
set line!linenumber!SrcNPA=%1
set line!linenumber!SrcNNX=%2
set line!linenumber!destNPA=%3
set line!linenumber!destNNX=%4
REM then intended to compare the values but I'm stuck
REM I want to compare the last arugment of each line to the same
REM same argument in the next line read, and if its sequential 
REM then set the start the range and when the comaparison is no longer
REM consecutive set the top of the range andn then write that range to output
set /a lineNumber+=1
4

1 に答える 1

3

連続する値を探すには、4番目の数値を計算する必要があります。おそらく、いくつかの数字はゼロから始めることができます。SET / Aは、0で始まる数値が8進表記であると想定しているため、これによりバッチの解析の問題が発生します。したがって、それを防ぐために追加の作業が必要です。

入力ファイルが事前にソートされていると仮定すると、次のように機能するはずです。

@echo off
setlocal enableDelayedExpansion
set "current="
set "next="
(
  for /f "tokens=1-4 delims=," %%A in (testFile.txt) do (
    set /a "num=10000%%D%%10000"
    if "!current!,!next!"=="%%A,%%B,%%C,!num!" (
      set "end=%%D"
      set /a "next+=1"
    ) else (
      if defined current echo !current!,!start!,!end!
      set "current=%%A,%%B,%%C"
      set "start=%%D"
      set "end=%%D"
      set /a "next=num+1"
    )
  )
  if defined current echo !current!,!start!,!end!
)>global_new.txt

入力ファイルが事前にソートされていない場合は、各列の幅が一定である限り、FOR/FでSORTを使用できます。

for /f "tokens=1-4 delims=," %%A in ('sort testFile.txt') do (

列の幅が一定でなく、ファイルが事前に並べ替えられていない場合、スクリプトははるかに複雑になります。その時点でVBSに切り替えることをお勧めします。とにかく、VBSのパフォーマンスははるかに向上します。

于 2012-05-17T05:39:15.853 に答える