如何在cmd中保存命令输出的单独部分

时间:2019-01-12 09:39:46

标签: shell batch-file cmd

我正在尝试仅在批处理文件中编写的命令的输出中保存一个值。

这是我已经编写的代码。

gencompress 01.dat > temp.txt

其输出如下所示。

Unconditionally compress 01.dat.
Searching for approximate repeats!
The compressed filename is 01.GEN!

0.005873%
..
93.733850%
99.982382%
..

 The size of original file is 17028 bytes.
 The size of compressed file is 4263 bytes.
 The compression ratio is 74.964764%.
    (defined by 1-|compressed_file|/|original_file|)

 Note: To verify the correctness of compression, you need follow the next two steps and then see what happens.
       1>  gendecompress  original_file.gen  [-c reference_file] 
       2>  comparetwofile  original_file  original_file.out 

但是我只想将值 4263 (位于输出中间的压缩文件的大小)存储到文本文件中。我如何从输出中检索该值。

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

过滤相关行的输出并使用正确的令牌:

for /f "tokens=7" %%a in ('gencompress 01.dat^|find "size of compressed"') do >temp.txt echo %%a
相关问题