'How to modify lines that hold a given string with new information and save it as a text file

I am working on modifying our batch files where we call @make functions inside. We want to add a script inside the batch file that checks an external header file, finds the line with date information(APP_VERSION_DATE) and updates the information there with new date information(I figured out how to fetch windows date information with batch, this is not an issue)

I know what steps to follow but batch syntax feels completely counter intuitive to me and I am stuck.

These are the steps I would like to follow:

1- Go through the app_version.h file line by line(for /f)

2- Find the lines with string APP_VERSION_DATE(if findstr...)

3- delete everything except APP_VERSION_DATE

4- CONCAT date information to APP_VERSION_DATE like APP_VERSION_DATE "23-05-2022"

5- Keep echoing every other line

6- Pipeline the information a new header file.

7- Delete header file

8- Rename the new header line as the old one.

set strToFind="app_version_date"
set result="Not Found"
for /f "tokens=2 delims=[]" %%A in ('findstr %strToFind% %filename%') do (
      set result=%%A
      if defined result (
           if  %result%==this is something 
           echo hurra this is it
      ) ELSE echo    
)

this is where I am at right now and I am obviously still too far off to do something I want to do.

I am able to make a program that can find a given string in a file and change it but in this case I want to find the line that has the string I am searching for, delete the rest and modify it. I want to find the line where the string is and modify it, not the string itself. This is simply because date information as shown below;

#define APP_VERSION_DATE [2022-05-16 12:13]

won't be static and ever changing with each compile attempt.

I have something like this but this is too far from what I want to do.

Any help would be great! Thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source