我想知道是否有一种方法可以将每个字符串从批处理语言的txt文件中放入变量,例如:
Alim.txt文件:
Instructions for updating:
Colocations handled automatically by placer.
2019-05-26 06:00:59.907030: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-05-26 06:00:59.930062: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 1992000000 Hz
2019-05-26 06:00:59.931310: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x740fd20 executing computations on platform Host. Devices:
2019-05-26 06:00:59.931349: I tensorflow/compiler/xla/service/service.cc:158] StreamExecutor device (0): <undefined>, <undefined>
('police', ' : ', '99.86363053321838')
('pilot', ' : ', '0.13637046795338392')
('firefighter', ' : ', '1.232255097960433e-06')
time required for executing this fuction : 6.337834449000184
memory use: 0.4300689697265625
CPU usage : 0.0
1 function calls in 0.000 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
结果:
381b4222-f694-41f0-9685-ff5bb260df2e Utilisation_normale
8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c Performances_élevées
a1841308-3541-4fab-bc81-f71556f20b4a Économie_d'énergie
,如果可能的话,请加上计数
以一种简单的方式,我在Batchl中不是很好。我将不胜感激
答案 0 :(得分:0)
您可以使用以下脚本完成此操作:
@echo off
setlocal enabledelayedexpansion
set _count=0
for /f "tokens=1* delims= " %%a in ('type Alim.txt') do (
set /a _count=!_count!+1
set var!_count!=%%a
set /a _count=!_count!+1
set var!_count!=%%b
)
setlocal enabledelayedexpansion
启用延迟扩展,以允许在for
循环内设置变量。set _count=0
创建一个用于设置变量的计数器变量。type Alim.txt
打印Alim.txt
文件的内容。for /f "tokens=1* delims= " %%a in ('...') do
遍历Alim.txt
中的每一行,按空格分隔并将这些部分保存到%%a
和%%b
。set /a _count=!_count!+1
递增_count
变量。set var!_count!=%%a
和set var!_count!=%%b
根据当前的_count
变量(例如:var1=381b4222-f694-41f0-9685-ff5bb260df2e
)设置一个变量。