我需要通过批处理脚本从文本文件中读取特定的单词。假设我想要读取第 2 行第 3 字。
这是代码::
@ECHO OFF
cls
SET /P line=Please enter Line number:
ECHO Line number entered is : %line%
SET /P word=Please enter Word number:
ECHO Word number entered is : %word%
FOR /F "tokens=%word% skip=%line% delims=," %%G IN (E_dir.txt) DO echo Chosen word is: %%G
问题是,这给了我从第 2 行开始的所有第 3 个单词。(例如,用户输入是第 1 行,第 3 个单词)。行数有问题,但我可以处理。我的问题是当我只需要第 2 行和第 3 行的单个单词时,它给了我所有的单词。
输入文件:E_Dir.txt
January,Snowy,02
February,Rainy,15
March,Sunny,25
April,Test,20
输出:
Please enter Line number: 1
Line number entered is : 1
Please enter Word number: 3
Word number entered is : 3
Chosen word is: 15
Chosen word is: 25
Chosen word is: 20
预期输出:
Please enter Line number: 1
Line number entered is : 1
Please enter Word number: 3
Word number entered is : 3
Chosen word is: 15