Reputation: 6018
I have a text file that has a number in every new line and all are in ascending order.
Contents are like :
1
13
25
37
49
97
109
121
I want to extract only those numbers who have difference greater than 12, with the previous number. I wish to use batch program for this....
How can I do that ?
Upvotes: 0
Views: 2892
Reputation: 65555
I would have liked to see you make an attempt but anyway I had a go and this is the closest I could get
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>
using this code in 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"
)
Upvotes: 2