You are not logged in.

#1 02 Oct 2015 14:24

thado77
Member
Registered: 02 Oct 2015
Posts: 8

I need help on this(subtract numbers from txt)

Please guys help me .
I need a batch that reads from txt file the contents and performs the operation e.g.
I have this txt ( subtract.txt) which contains the following
5-3
2-5
6-2

I need a new txt that will contain the reults of the above operations :
2
-3
4
... Please help me.

Offline

#2 02 Oct 2015 15:56

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 446

Re: I need help on this(subtract numbers from txt)

not tested:


@echo off
setlocal enableDelayedExpansion
break>result.txt
for /f "usebackq tokens=*" %%# in ("subtract.txt") do  (
  set /a result=%%#
  echo !result!>>result.txt
)

Offline

#3 02 Oct 2015 16:15

thado77
Member
Registered: 02 Oct 2015
Posts: 8

Re: I need help on this(subtract numbers from txt)

npocmaka Thank u so much for your answer and for your time also. I tried it but all I get in result.txt is "ECHO is off". and when I try to execute it from cmd I get "Missing operand".

Offline

#4 02 Oct 2015 16:21

Aacini
Member
Registered: 05 Dec 2012
Posts: 149

Re: I need help on this(subtract numbers from txt)

@echo off
setlocal enableDelayedExpansion
(for /f "usebackq tokens=*" %%# in ("subtract.txt") do  (
  set /a result=%%#
  echo !result!
)) >result.txt

This way the process is more efficient...

Last edited by Aacini (02 Oct 2015 16:33)

Offline

#5 02 Oct 2015 16:26

thado77
Member
Registered: 02 Oct 2015
Posts: 8

Re: I need help on this(subtract numbers from txt)

It's my fault and I apologize. I gave you an example with small numbers. I actually want to operate numbers such :
105363-105200
78088-78056
153767-153318
129813-129813
149096-149096
129409-129408
136272-136272
95499-95467
135883-135787
120275-120949

I tried with small numbers the two codes from Aacini and npocmaka and  both work (thank u so much). But with the numbers above it doesn't. Any suggesion ?

Offline

#6 02 Oct 2015 16:31

Aacini
Member
Registered: 05 Dec 2012
Posts: 149

Re: I need help on this(subtract numbers from txt)

It works here!

C:\> test.bat

C:\> type result.txt
163
32
449
0
0
1
0
32
96
-674

Last edited by Aacini (02 Oct 2015 16:32)

Offline

#7 02 Oct 2015 16:32

thado77
Member
Registered: 02 Oct 2015
Posts: 8

Re: I need help on this(subtract numbers from txt)

I'll figure it out Aacini .... Maybe something I did wrong. Thank you for your precious time...

Offline

#8 02 Oct 2015 17:58

thado77
Member
Registered: 02 Oct 2015
Posts: 8

Re: I need help on this(subtract numbers from txt)

IT worked.... !!!!  big_smile  big_smile  big_smile
There was something wrong with my pc.... !!! Thank you npocmaka , thank you Aacini !!! Thank you for your effort and for your time... !!! big_smile  big_smile  big_smile

Offline

Board footer

Powered by