本文介绍了批次 - 使用FINDSTR读取文件条目和输出,如果它小于一个可变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图读取使用FINDSTR输出基于价值是否低于我的predefined数值只有特定字符的文本文件。下面是从我试图读取文本文件中的行:

I'm trying to read a text file using findstr to output only specific characters based on whether the value is less than my predefined number value. Here is a line from the text file that i am trying to read:

BW6556 *NULL* 1 6 1406922741 1407046596 1415081796 0 845292618 3 3 5 5 0 8 1024

BW6657 *NULL* 1 6 1408817016 1408817016 1416852216 0 193816666 2 2 5 5 0 0 1024

我需要一个前pression自己看上面一行并执行以下操作:

I need an expression that looks at the above line and does the following:


  1. 着眼于每个开始于角色41,结束于50字符
  2. 线长号
  3. 如果这个数字大于1且小于我的变量数量%expirydate%,那么写出来的字1-7到一个新的文件。

  4. 做同样的事情在文本文件中的每一行!

任何想法?

推荐答案

这不能与FINDSTR完成。首先,FINDSTR不能数值比较数字。其次,FINDSTR不能从线返回一个字符串。

That cannot be done with FINDSTR. First off, FINDSTR cannot numerically compare numbers. Second, FINDSTR cannot return a substring from a line.

可以使用FOR / F来分析价值的空间分隔的列表来解决。请注意,此溶液不是基于字符位置。

It can be solved using FOR /F to parse the space delimited list of values. Note that this solution is not based on character position.

编辑: 主要重写处理超过2147483647此外,如果它在中间的零点我原来的code不合格数量较多的可能性数

本解决方案假定所有线路都在7令牌(41位),10位数字。我附上了IF内比较引号中的值,迫使它做一个文本的比较,而不是数值比较。这将正常工作,只要所有的值恰好有10位。

This solution assumes all lines have 10 digits in the 7th token (position 41). I enclose the values in quotes within the IF comparison to force it to do a text comparison instead of a numeric comparison. This will work properly as long as all values have exactly 10 digits.

set "num=0000000000%expirydate%"
set "num=%num:~-10%"
for /f "usebackq tokens=1,7" %%A in ("test.txt") do (
  if "%%C" gtr "0000000001" if "%%C" lss "%expirydate%" (echo %%A )
)

这篇关于批次 - 使用FINDSTR读取文件条目和输出,如果它小于一个可变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 00:38