Vbscript 查找线路&;编辑它
我在这上面贴了另一张,但我不得不对它进行大量编辑 基本上,批处理(可能包括VBScript)可以在TXT文件中找到第29行。。。它应该编辑这一行 如果第29行是这样的:“option=21”,则应将其更改为“option=22” 问题是这一行更多地位于文件中。所以它应该只编辑第29行 怎么办Vbscript 查找线路&;编辑它,vbscript,batch-file,edit,text-files,lines,Vbscript,Batch File,Edit,Text Files,Lines,我在这上面贴了另一张,但我不得不对它进行大量编辑 基本上,批处理(可能包括VBScript)可以在TXT文件中找到第29行。。。它应该编辑这一行 如果第29行是这样的:“option=21”,则应将其更改为“option=22” 问题是这一行更多地位于文件中。所以它应该只编辑第29行 怎么办 [请不要使用自定义程序;;;它应该由每个用户在不安装任何东西的情况下完成。好的。我知道您要求的是vb脚本, 使用AWK,它会变成这样, 也许它会帮助你编写vb awk'{if(FNR==29){gsub(/
[请不要使用自定义程序;;;它应该由每个用户在不安装任何东西的情况下完成。好的。我知道您要求的是
vb
脚本,使用
AWK
,它会变成这样,也许它会帮助你编写
vb
awk'{if(FNR==29){gsub(/option=21/,“option=22”);print}else{print$0;}}'input.txt>output.txt
没有试过,所以可能有一些轻微的故障
FNR=29
将仅在第29行检查处理gsub
将用gsub
option=22
- 其他线路将通过
我知道你要的是
vb
脚本,使用
AWK
,它会变成这样,也许它会帮助你编写
vb
awk'{if(FNR==29){gsub(/option=21/,“option=22”);print}else{print$0;}}'input.txt>output.txt
没有试过,所以可能有一些轻微的故障
FNR=29
将仅在第29行检查处理gsub
将用gsub
option=22
- 其他线路将通过
这不是您通常成批执行的操作,但非常简单:
@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
如果你想调整它,它应该为你指明大致的方向。这不是你通常批量做的事情,但它相当简单:
@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
如果您想调整它,它应该为您指出大致的方向。这里有一个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
这里有一个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
当用户登录时,您不能通过gpo或其他方式推送它吗?或者这也不是一个理想的情况?基本上,从公共网络共享中复制文件,并使用正确的文本覆盖用户计算机上的文件,无论该文件位于何处?当用户登录时,您不能通过gpo或其他方式推动该文件吗?或者这也不是一个理想的情况?基本上,从公共网络共享中复制文件并使用正确的文本,然后在用户计算机上覆盖该文件,无论该文件位于何处?是的,我刚刚修复了我在视觉上发现的一些错误。我只想描述一下这个方案;awk命令可以缩短:gawk“FNR==29{gsub(/option=21/,\“option=22\”)}1”file.txt是的,我刚刚修复了我在视觉上捕捉到的一些错误。我只想描述一下这个方案;awk命令可以缩短:gawk“FNR==29{gsub(/option=21/,\“option=22\”)}1”file.txtyah问题出在哪里;'选项=22'应更改为“”。我发现应该是这样的:“^”我一直在寻找这个……谢谢!!!我希望我能把我所有的赏金都给你,因为我不能告诉你我尝试了多久。是的,问题是什么;'选项=22'应更改为“”。我发现应该是这样的:“^”我一直在寻找这个……谢谢!!!我希望我能把我所有的赏金都给你,因为我不能告诉你我为此付出了多少努力。