jrepl: replace + append in cmd file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
solquest
Posts: 1
Joined: 12 Nov 2020 11:31

jrepl: replace + append in cmd file

#1 Post by solquest » 12 Nov 2020 11:39

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!

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: jrepl: replace + append in cmd file

#2 Post by dbenham » 12 Nov 2020 18:10

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

Post Reply