FINDSTR (Find & Replace) question...
Moderator: DosItHelp
-
- Posts: 38
- Joined: 04 Apr 2012 03:11
FINDSTR (Find & Replace) question...
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?
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...
Does any other line start with "FILE" in the cue file?
-
- Posts: 38
- Joined: 04 Apr 2012 03:11
Re: FINDSTR (Find & Replace) question...
Luckily no! And its always in UPPERCASE lettering.
Re: FINDSTR (Find & Replace) question...
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.
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
-
- Posts: 38
- Joined: 04 Apr 2012 03:11
Re: FINDSTR (Find & Replace) question...
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?
@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...
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.
Try putting the SED files in the same folder as the batch file, as an immediate workaround.
-
- Posts: 38
- Joined: 04 Apr 2012 03:11
Re: FINDSTR (Find & Replace) question...
No dosn't seem to have any effect...
-
- Posts: 43
- Joined: 20 Mar 2012 20:53
Re: FINDSTR (Find & Replace) question...
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...
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
Nice use of move! That's a keeper.
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...
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...
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