batch file - use find/replace with formula -


This is a very simple question, but goes here.

I have to find a file in a certain order, then add 5 in each number / east:

time hour: 1, cent: 2, ps: 10 (which is I'm looking for - other types of other types would be numbers across the file)

I would like to change the numbers with 5 + 5

time hour: 6, cents: 7, p S: 15

Batch is not optimal choice for text processing, especially according to your requirement. Something in the til form This can be done more simply by using JScript, VBScript, or powershell but it is possible with batch ...

There is no batch command what you can do. To read each line, you have to type your code, and if it does not match the format, then write it unchanged. If it matches the format, then parse the line to remove the number, use SET / A to increase them, and type the new line.

You can not modify your file directly instead you should type in a temporary file. When finished, move the temporary file to the original name.

I will assume that the formatted text of interest has not been embedded in a large row.

You can not give any indication of other content as empty rows within the file and maybe exclamation points can cause problems. I think they can be present, so if there is no code, this is a lot more complicated than the requirement of code.

I protect empty rows by using FINDSTR / N to insert a line number prefix for each line. This prefix should be stripped before writing this file to a new file.

The exclamation points are safe by turning delayed extensions inside and off the loop on and off. If the delayed extension has been extended, when a variable is expanded, the value can be corrupted if it has an exclamation point.

  Disable @echo off setlocalTranslated Expandement & gt; For "yourFile.txt.new" (for / f "delims =:, tokens = 1-7 *" %% a in ("%") / ("findstr / n" ^ "yourfile.txt"% L ") (if" %% B %% D %% F %% H "is" TimeHR STS "(set / one" hr = %% c +5, cents = %% e +5, ps = %% g + 5 "setlocal enableDelayedExpansion echo time! HR !, st :! cents !, ps:! Ps! Andalocal) Other (Set" LN = %% L "Settleoscal enabled delimited exponent (! Ln: *: =! Endlocal) ))): Steps / Y "yourFile.txt.new" "yourFile.txt" & gt; Null type yourFile.txt.new  

Comments