我想在Windows XP中使用dos批处理文件编程在已存在的文本文件中的特定行写入一行文本。我也想从用户输入行号。任何帮助将不胜感激。windows批处理文件编程
2
A
回答
4
实例提示用户:
:MENU
SET /P TYPE=Type the line number and press enter:
if "%TYPE%"=="1" goto ONE
if "%TYPE%"=="2" goto TWO
if "%TYPE%"=="3" goto THREE
if "%TYPE%"=="4" goto FOUR
if "%TYPE%"=="5" goto FIVE
goto MENU
注:对于使用-L选项可以产生较大的交叉检查命令; 欲了解更多信息,请键入c:> FOR /?
FOR IN/L%变量(开始,步骤,结束)DO命令[命令参数]
The set is a sequence of numbers from start to end, by step amount.
So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would
generate the sequence (5 4 3 2 1)
FOR/L %%一个IN(1,1,1000)DO如果“%TYPE %“==” %%一个”转到:VALIDNUM
@echo off
rem this only prompts the user for a number
set VALIDNUM=
:MENU
cls
echo.
echo.
If NOT "%VALIDNUM%"=="" echo the number is %VALIDNUM%
echo.
SET /P TYPE=Type a line number and press enter:
FOR /L %%a IN (1,1,1000) DO if "%TYPE%"=="%%a" set VALIDNUM=%TYPE%
goto MENU
3
也许你不应该使用批处理。或者,也许你不应该使用批处理。
也许这样的事情可能会起作用。我没有经过测试。
setlocal enabledelayedexpansion
SET /a counter=0
echo. > newfile
for /f "usebackq delims=" %%a in (yourfile.txt) do (
if "!counter!"=="%1" echo "YOUR SPECIFIC LINE" >> newfile
if not "!counter!"=="%1" echo %%a >> newfile
set /a counter+=1
)
move newfile yourfile.txt
但是,如果您使用的是DOS而不是Windows NT的版本,它将无法正常工作。 (如果你使用的是Windows,而不是DOS编辑标记)
2
用户advanced batch file editor Dr.Batcher,你就可以只是点击几下创建这样的脚本!
相关问题
- 1. 编程批处理文件
- 2. 批处理文件编程
- 3. 如何编写Windows批处理文件
- 4. 编译CLASSPATH在Windows批处理文件
- 5. windows批处理文件编程 - 获取COMPORT编号
- 6. 批处理文件的Windows
- 7. Windows批处理文件
- 8. Windows批处理文件处理 - 循环
- 9. cmd编程批处理文件循环
- 10. 如何从Windows批处理文件编辑文本文件?
- 11. 在Windows下使用批处理文件编辑文本文件
- 12. 批处理文件 - 关闭通过批处理文件过程
- 13. 使用powershell编辑Windows批处理文件中的文件
- 14. 带批处理的Windows批处理文件夹循环
- 15. Windows,批处理文件时间条件
- 16. Windows批处理文件循环通过目录处理文件?
- 17. 批处理编程中的文件处理?
- 18. Windows批处理
- 19. 批处理文件在Windows中运行其他批处理文件
- 20. 如何从另一个批处理文件调用Windows批处理文件
- 21. Windows批处理文件:if else
- 22. Windows批处理文件中的变量
- 23. Windows批处理文件'cut'like feature
- 24. Windows批处理文件不验证年
- 25. windows批处理文件:psexec和findstr
- 26. Windows批处理文件语法
- 27. 从Windows批处理文件解析URL
- 28. 嵌套在Windows批处理(* .bat)文件
- 29. Windows批处理文件扩展变量
- 30. 串联在Windows批处理文件
感谢您的回复。我正在使用Windows XP。我打算为此写一个批处理文件。我尝试过这个。但是“!”符号会导致错误。我想在已经存在的文本文件的特定行中写入一行文本。同时我需要输入行号。来自user.Now此代码清除我现有的文件。更多帮助? – 1355 2010-09-17 10:47:41
第六行应该是,如果不是“!counter!”==“%1”echo %% a >> newfile – 2010-09-17 15:06:53
是的,我很久没有触及批处理。修正了。可以自由编辑我的帖子,为其他错误。 – BatchyX 2010-09-17 17:00:49