Windowsバッチファイルの90%はそこにあります。 2つの入力パラメータ、入力ファイルと出力ファイルが必要です。 次に、入力ファイルを読み込み、特定の行を配列にサブストリングします(ウェルライン2以降)。 次に出力のためのループに来ます。 !counter2!を使用しない限り、アレイを通過するための私のカウンタの遅延拡張は更新されません。%counter2%は機能しません。Windowsバッチファイルを読み込み、解析して出力します
を使用しています!arrayname [!counter2!]!動作しません。
ここにコードを示します。
@Echo off
if [%1] == [] goto usage
if [%2] == [] goto usage
echo start time : %time%>logfile.log
set input_file=%1
set output_file=%2
if exist %output_file% del %output_file%
Echo Start reading %input_file%>> logfile.log
setLocal EnableDelayedExpansion
set /a counter=1
for /F "tokens=* delims=" %%a in ('type %input_file%') DO (
::echo !counter!
if "!counter!"=="1" set header=%%a
if not "!counter!"=="1" (
set data[!counter!]=%%a
set line=%%a
set jobnumber[!counter!]=!line:~0,7!
set docnumber[!counter!]=!line:~7,5!
set pagecount[!counter!]=!line:~12,2!
set customernumber[!counter!]=!line:~14,20!
set presort[!counter!]=0000
set postcode[!counter!]=0000
set inserts[!counter!]=!line:~36,11!
set filler[!counter!]=000000
set address[!counter!]=!line:~58,350!
set filler2[!counter!]=" "
set endline[!counter!]=X
)
set /a counter=counter+1
)
Echo Start writing %output_file%>> logfile.log
for /L %%G in (2,1,%counter%) DO (
set counter2=%%G
echo !counter2!
echo !jobnumber[%counter2%]!!docnumber[%counter2%]!!pagecount[%counter2%]!!customernumber[%counter2%]!!presort[%counter2%]!!postcode[%counter2%]!!inserts[%counter2%]!!filler[%counter2%]!!address[%counter2%]!!filler2[%counter2%]!!endline[%counter2%]!>>%output_file%
)
echo end time : %time%>>logfile.log
pause
goto :eof
:usage
echo Usage: blah.bat input_filename output_filename
pause
goto :eof
エコー!ジョブ番号[%カウンタ2%]です!物事は解決されていません。 echo!counter2!正常に動作します。
質問する前に、はい、これはC#や別のプログラミング言語でうまくやればいいとわかっていますが、Windowsのバッチファイルでやってみることになっています。
ご協力いただきありがとうございます。 電話
しかし、あなたは直接 '!jobnumber [%% G]!'を使用することができます... – npocmaka
Ahhh Right。私の最初のループでは動作しませんでしたが、それはカウンタが変化しているためです。どうもありがとう。 – telsum2