Batch To Find Text & Add New Line Of Text

Microsoft Windows xp professional w/sp2
April 6, 2010 at 17:53:09
Specs: Windows
I need help to create (I am too stoopid) a batch to search the directory including sub folders for a *.cue file, when found search inside the *.cue for the string ( TITLE "*") then add on the next line ( FLAGS DCP)

note: minus the brackets, including the 4 spaces in front as follows.


INDEX 01 00:00:00


INDEX 01 00:00:00

It also needs to continue to the end of document, adding the new line at each occurrence before saving and continuing to the end of the directory/sub folders

See More: Batch To Find Text & Add New Line Of Text

Report •

April 6, 2010 at 18:53:59
@echo off>temp & setlocal enabledelayedexpansion
for /f %%a in (*.cue) do (
find /c /i "Title " %%a >nul
if !errorlevel! gtr 0 call :repl %%a
goto :eof
for /f "tokens=*" %%b in (%1) do (
>> temp echo %%b
if /i '%%b' equ 'title "*"' >> temp echo FLAGS DCP
echo done processing: %1
echo check file! no "suprises" are allowed!
more %1
::disabled until testing is verified
::move /y temp %1
::------ end of script
not tested (hence all the safeties).
run tests first, note that any blank lines will disappear,
and if >, < or ! appears in file, there will be problems.
sorry for this crappy code, i hope you get better responses. sorry

Report •

April 6, 2010 at 20:57:06
download findutils and sed from GNU win32. Then use this one liner

c:\test> gnu_find . -type f -iname "*.cue" -exec sed -i.bak "/TITLE/a FLAGS DCP" "{}" ;

GNU win32 packages | Gawk

Report •

April 7, 2010 at 03:16:43
Thanks ghostdog but not interested in installing anything, hope that what I want to do can be achieved with what is already available to me.

Thanks nbrane, I tried the batch script with no luck, only the temp file was created and left behind after cmd.exe process had closed. I have been using it as a base with still no luck.

Just want to be clear that the * in the above example represents a wildcard (* is different in each file name and at every occurrence of TITLE "*" in the document)

Report •

Related Solutions

April 7, 2010 at 03:53:33
@notmetoo, just for your info, both gnu find and sed are executables by themselves. you only have to download them ONCE and you can use them next time you are doing similar stuffs. they will really enhance your batch experience and they are also portable and you can distribute them on a usb drive and bring anywhere. start being productive today.

GNU win32 packages | Gawk

Report •

April 7, 2010 at 05:03:47
@echo off > newfile & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/s/b/a-d *.cue') do (
for /f "tokens=1* delims= " %%i in (%%a) do (
>> newfile echo.%%i %%j
if "%%i" equ "Title" >> newfile echo FLAGS DCP
move /y newfile "%%a"

Helping others achieve escape felicity


Report •

Ask Question