Page 1 of 1

jrepl: replace + append in cmd file

Posted: 12 Nov 2020 11:39
by solquest
Hey there.

In a cmd file I need to
- replace one string with another in a txt file
- append string '.jpg' to every single row of the same txt file

I've done the first part with

Code: Select all

set "excludeFile=C:\BBB\CCC\list.txt"
set "newExcludeFile=C:\BBB\CCC\list_new.txt"
set "SEARCHTEXT=\AAA\"
set "REPLACETEXT=\EEE\AAA\"

if exist "%newExcludeFile%" del "%newExcludeFile%"
call jrepl "%SEARCHTEXT%" "%REPLACETEXT%" /x /m /l /f "%excludeFile%" /o "%newExcludeFile%"
How can I do the second part, possibly without iterating again all the rows of the "%excludeFile%"?

Thanks!

Re: jrepl: replace + append in cmd file

Posted: 12 Nov 2020 18:10
by dbenham
You definitely don't want the /M option if you are trying to process lines.

I also don't see the purpose of /X in your case, but I don't see that it hurts either.

If you specify your search as a regex, then you could use the /T option, including a search/replace for end of line. The regex is needed to specify $ for end of line in the search.

But you want to do a literal search, meaning $ is unavailable and /T won't work.

The simplest solution is to use /JENDLN to add .jpg to the end of each line.

Since you are storing all your options in variables, you might as well use the /V option

Code: Select all

set "excludeFile=C:\BBB\CCC\list.txt"
set "newExcludeFile=C:\BBB\CCC\list_new.txt"
set "SEARCHTEXT=\AAA\"
set "REPLACETEXT=\EEE\AAA\"
set "JENDLN=$txt+='.jpg'"

if exist "%newExcludeFile%" del "%newExcludeFile%"
call jrepl SEARCHTEXT REPLACETEXT /jendln JENDLN /v /x /l /f excludeFile /o newExcludeFile

Dave Benham