Batch file 从文本文件中提取特定位置的子字符串并将其分配给环境变量
我有一个文本文件Batch file 从文本文件中提取特定位置的子字符串并将其分配给环境变量,batch-file,Batch File,我有一个文本文件text.txt。该文件的内容是: 我需要(通过命令行)提取部分12.0.1.61053 该值位于第一行的位置25到36。 我需要将此值插入环境变量。这非常简单。代码假定text.txt与脚本位于同一目录中 @echo off :: Get the first line of text.txt and store the entire thing in a variable set /p first_line=<text.txt :: Get an 11-charact
text.txt
。该文件的内容是:
我需要(通过命令行)提取部分12.0.1.61053
该值位于第一行的位置25到36。我需要将此值插入环境变量。这非常简单。代码假定text.txt与脚本位于同一目录中
@echo off
:: Get the first line of text.txt and store the entire thing in a variable
set /p first_line=<text.txt
:: Get an 11-character substring starting at position 25 (substrings start at 0)
set first_line=%first_line:~24,12%
echo %first_line%
@echo关闭
::获取text.txt的第一行并将整个内容存储在变量中
设置/p第一行=可能的重复项。在发布新问题之前,请花时间至少对类似的现有问题进行基本搜索。谢谢。还有一个程序员对程序员的网站,帮助其他程序员解决问题。所以你应该展示你已经尝试了什么,以及你的方法有什么问题。这就是当你在太多的地方匆忙地用一个数字来弥补损失时会发生的情况。
@echo off
:: Get the first line of text.txt and store the entire thing in a variable
set /p first_line=<text.txt
:: Get an 11-character substring starting at position 25 (substrings start at 0)
set first_line=%first_line:~24,12%
echo %first_line%