从文本文件中提取特定位置的子字符串并分配给环境变量

时间:2021-03-04 19:24:50

I have a text file text.txt. The content of the file is:

我有一个文本文件text.txt。该文件的内容是:

--a-- W32i   APP ENU    12.0.1.61053 shp

I need to extract (via command line) the portion 12.0.1.61053.

我需要提取(通过命令行)部分12.0.1.61053。

This value is in the first line, at position 25 to 36.
I need to insert this value into an environment variable.

该值位于第一行,位于25到36.我需要将此值插入环境变量中。

1 个解决方案

#1


1  

This is pretty straightforward. The code assumes that text.txt is in the same directory as your script.

这非常简单。该代码假定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%

#1


1  

This is pretty straightforward. The code assumes that text.txt is in the same directory as your script.

这非常简单。该代码假定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%