FINDSTR (Find & Replace) question...

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
phoenix_Rising
Posts: 38
Joined: 04 Apr 2012 03:11

FINDSTR (Find & Replace) question...

#1 Post by phoenix_Rising » 17 Apr 2012 08:14

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?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: FINDSTR (Find & Replace) question...

#2 Post by foxidrive » 17 Apr 2012 08:18

Does any other line start with "FILE" in the cue file?

phoenix_Rising
Posts: 38
Joined: 04 Apr 2012 03:11

Re: FINDSTR (Find & Replace) question...

#3 Post by phoenix_Rising » 17 Apr 2012 08:21

Luckily no! :) And its always in UPPERCASE lettering.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: FINDSTR (Find & Replace) question...

#4 Post by foxidrive » 17 Apr 2012 08:24

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

phoenix_Rising
Posts: 38
Joined: 04 Apr 2012 03:11

Re: FINDSTR (Find & Replace) question...

#5 Post by phoenix_Rising » 17 Apr 2012 09:33

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?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: FINDSTR (Find & Replace) question...

#6 Post by foxidrive » 17 Apr 2012 10:02

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.

phoenix_Rising
Posts: 38
Joined: 04 Apr 2012 03:11

Re: FINDSTR (Find & Replace) question...

#7 Post by phoenix_Rising » 17 Apr 2012 16:32

No dosn't seem to have any effect...

MrKnowItAllxx
Posts: 43
Joined: 20 Mar 2012 20:53

Re: FINDSTR (Find & Replace) question...

#8 Post by MrKnowItAllxx » 17 Apr 2012 20:27

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

Ocalabob
Posts: 79
Joined: 24 Dec 2010 12:16
Location: Micanopy Florida

Re: FINDSTR (Find & Replace) question...

#9 Post by Ocalabob » 18 Apr 2012 17:20

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: FINDSTR (Find & Replace) question...

#10 Post by foxidrive » 19 Apr 2012 00:48

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: FINDSTR (Find & Replace) question...

#11 Post by foxidrive » 19 Apr 2012 00:50

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

Post Reply