0

我有一个文本文件,每个新行都有一个数字,并且都按升序排列。

内容如下:

1
13
25
37
49
97
109
121

我只想提取与前一个数字相差大于 12 的数字。我希望为此使用批处理程序....

我怎样才能做到这一点 ?

4

1 回答 1

2

我很想看到你尝试,但无论如何我试了一下,这是我能得到的最接近的

c:\temp>type test.txt
1 line 1
10 line 1a
13 line 2
25 line 3
22 line 3a
37 line 4
49 line 5
97 line 6
109 line 7
121 line 8

c:\temp>test.bat
25 line 3
37 line 4
49 line 5
97 line 6
109 line 7
121 line 8

c:\temp>

在 test.bat 中使用此代码:

@echo off

SETLOCAL ENABLEDELAYEDEXPANSION

set /a cur="0"
for /f "tokens=1,* delims= " %%a in ('type test.txt') do (

  set line=%%a %%b   

  set /a num="%%a"
  set /a dif="!num!-!cur!"

  if !dif! geq 12 @echo !line!

  set /a cur="%%a"
)
于 2012-12-25T12:02:19.317 回答