-4

I want to search a string in a .txt .

After identifying the line need to add another string at the end of the line...

Please Help

Example:

(
echo 3-Trip-7000-23 
echo 6-Lunch-600-2 
echo 7-Breakfast-15-5
) > FILE.txt

If i type Lunch it prints in that case Lunch-600-2 because search the string "Lunch" in the file, how do I have to code that... Im in windows

N. Mansch
  • 25
  • 1
  • 5

1 Answers1

0

set variables at the top, i made this for automating rom building for decompiled framework

@echo off
setlocal enableextensions enabledelayedexpansion
set search=search for this string
set file=searchfile.txt
set addstring=add this string to the line

set count=0
for /F "usebackq tokens=*" %%A in ("%file%") do (
set /A count+=1
Echo.%%A | findstr /C:"%search%">nul && (set magicnumber=!count!)
)
set count=0
for /F "usebackq tokens=*" %%A in ("%file%") do (
set /A count+=1
if !count! == %magicnumber% echo %%A%addstring% >>tmp.txt
if !count! == %magicnumber% set line=%%A
if not !count! == %magicnumber% echo %%A >>tmp.txt
)
del /Q %file%
ren "tmp.txt" "%file%"
echo "%search%" is on line %magicnumber% and line has been changed to "%line%%addstring%"