Page 1 of 1
FINDSTR (Find & Replace) question...
Posted: 17 Apr 2012 08:14
by phoenix_Rising
Im looking at re-creating my audio .cue files for compatibility's sake and have to read a line of data from the .cue file with the (FINDSTR command?) which is always laid out in the same way but with 3 variations to the string:
eg.(from test.cue)
FILE "Johnsmiths.ape" APE
eg. (from test2.cue)
FILE "Johnsmiths.flac" FLAC
eg. (from test3.cue)
FILE "Johnsmiths.wv" WV
What i need to do is create a findstr command that will:
Look for the word 'FILE' > Replace it with:
FILE "CDIMAGE.wav" WAVE
Any ideas?
Re: FINDSTR (Find & Replace) question...
Posted: 17 Apr 2012 08:18
by foxidrive
Does any other line start with "FILE" in the cue file?
Re: FINDSTR (Find & Replace) question...
Posted: 17 Apr 2012 08:21
by phoenix_Rising
Luckily no!

And its always in UPPERCASE lettering.
Re: FINDSTR (Find & Replace) question...
Posted: 17 Apr 2012 08:24
by foxidrive
This uses GNU sed for Windows.
As long as FILE is only at the start of one line in the cue files then it will work.
@echo off
for /f "delims=" %%a in ('dir *.cue /b /s') do (
sed "s/^FILE .*/FILE \x22CDIMAGE.wav\x22 WAVE/" "%%a" >temp.tmp
move /y temp.tmp "%%a" >nul
)
pause
Re: FINDSTR (Find & Replace) question...
Posted: 17 Apr 2012 09:33
by phoenix_Rising
Just installed the GNU SED pack and copied the 4 files over to my tools folder (C:\ojw\tools) where i'm calling these commands from however when i ran the following command:
@echo off
for /f "delims=" %%a in ('dir c:\ojw\pending\*.cue /b /s') do (
c:\ojw\tools\sed.exe "s/^FILE .*/FILE \x22CDIMAGE.wav\x22 WAVE/" "%%a" >temp.tmp
move /y temp.tmp "%%a" >nul
)
pause
It seems to overwrite all the .cue files that were there in the folder c:\ojw\pending\*.* and writing no data to them leaving them empty and curiously with a locked padlock next to the icon within windows??
Do you know what the issue may be?
Re: FINDSTR (Find & Replace) question...
Posted: 17 Apr 2012 10:02
by foxidrive
Possibly because your tools folder is not on the path so SED cannot find its support files.
Try putting the SED files in the same folder as the batch file, as an immediate workaround.
Re: FINDSTR (Find & Replace) question...
Posted: 17 Apr 2012 16:32
by phoenix_Rising
No dosn't seem to have any effect...
Re: FINDSTR (Find & Replace) question...
Posted: 17 Apr 2012 20:27
by MrKnowItAllxx
Code: Select all
:substitute OldStr NewStr File -- substitutes a string in a text file
:: -- OldStr [in] - string to be replaced
:: -- NewStr [in] - string to replace with
:: -- File [in] - file to be parsed
:$created 20060101 :$changed 20101122 :$categories FileManipulation
:$source http://www.dostips.com
SETLOCAL DISABLEDELAYEDEXPANSION
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
set "line=%%B"
if defined line (
call set "line=echo.%%line:%~1=%~2%%"
for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
) ELSE echo.
)
EXIT /b
Could this not be converted to your needs??
Taken from
http://www.dostips.com/DtCodeCmdLib.php
Re: FINDSTR (Find & Replace) question...
Posted: 18 Apr 2012 17:20
by Ocalabob
Greetings phoenix_Rising,
If you have SED and its required files in your path then foxidrive's script will work properly on the example you provided. Should you have additional lines of text in your *.cue files and wish to keep them then remove the .* in the ^FILE .* portion of the script.
Best wishes phoenix_Rising!
@foxidrive
Code: Select all
>temp.tmp
move /y temp.tmp "%%a" >nul
)
Nice use of move! That's a keeper.
Re: FINDSTR (Find & Replace) question...
Posted: 19 Apr 2012 00:48
by foxidrive
Ocalabob wrote:Should you have additional lines of text in your *.cue files and wish to keep them then remove the .* in the ^FILE .* portion of the script.
Nice use of move! That's a keeper.
Thanks Ocalabob

I just want to comment that the .* will replace the entire line, which is needed. It will not affect any other lines unless they also match the ^FILE section.
Re: FINDSTR (Find & Replace) question...
Posted: 19 Apr 2012 00:50
by foxidrive
phoenix_Rising wrote:No dosn't seem to have any effect...
I missed seeing your reply.
Can you open a cmd prompt and type this?
sed --v