0

これに別のものを投稿しましたが、本当に編集する必要がありました...

基本的には、バッチ(おそらくVBScriptを含む)がtxtfileの29行目を見つけることができるということです...この行を編集する必要があります。

29 行目が「option=21」の場合、「option=22」に変更する必要があります。

問題は、この行がファイル内のより多くの場所にあることです。29行目を編集するだけです...

方法???

[カスタム プログラムはご遠慮ください;;; OK のものをインストールせずに、すべてのユーザーが実行する必要があります。]

4

3 に答える 3

3

これは通常、バッチで行うことではありませんが、かなり簡単です。

@echo off
setlocal enableextensions enabledelayedexpansion

rem the input file
set inputfile=file.txt

rem temporary file for output, we can't just write into the
rem same file we're reading
set tempfile=%random%-%random%.tmp

rem delete the temporary file if it's already there
rem shouldn't really happen, but just in case ...
copy /y nul %tempfile%

rem line counter
set line=0

rem loop through the file
for /f "delims=" %%l in (%inputfile%) do (
    set /a line+=1
    if !line!==29 (
        rem hardcoded, at the moment, you might want to look
        rem here whether the line really starts with "options"
        rem and just put another number at the end.
        echo option=22>>%tempfile%
    ) else (
        echo %%l>>%tempfile%
    )
)

del %inputfile%
ren %tempfile% %inputfile%

endlocal

適応させたい場合は、一般的な方向性を示す必要があります。

于 2009-07-12T10:18:36.207 に答える
0

ここにvbscriptがあります

Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "c:\test\file.txt"
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfStream
    linenum = objFile.Line
    strLine = objFile.ReadLine
    If linenum = 29 Then
        strLine = Replace(strLine,"option=21","option=22")
    End If
    WScript.Echo strLine
Loop    

使い方:

c:\test> cscript /nologo myscript.vbs > newfile
c:\test> ren newfile file.txt
于 2009-07-12T11:04:54.460 に答える