简体   繁体   English

使用批处理读取.txt文件,并提取()之间的字符串

[英]Read a .txt file using batch and extract a string between ()

I have a .LOG file whitch contains: 我有一个.LOG文件,其中包含:

2015-01-20 17:00:59 (15.6 MB/s) - `c:/temp/teste_velocidade.tar.gz' saved [253311/253311]

I'd like to extract the content between "(" ")" into a variable. 我想将“(”“)”之间的内容提取到一个变量中。

Ex.: 例:

$number=15.6
$unit=MB

How can I do This? 我怎样才能做到这一点?

I'm seaching for a solution for it but batch is not familiar to me. 我正在寻找解决方案,但我不熟悉批处理。

Like this : 像这样 :

@echo off

for /f "tokens=3,4 Delims=() " %%a in (test.log) do (
  set "$Number=%%a" 
  set "$Unit=%%b"
)

echo Number : [%$Number%]
echo Unit   : [%$Unit%]

I Used here a file named test.log for the test 我在这里使用了一个名为test.log的文件进行测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM