5

I found that solution below to replace strings, but I do not fully understand it.
How do I have to change the code to replace 3 strings per line?
My changes (line 12 and 13) aren't working yet.

Is it possible without running a second and third loop?

ECHO off
SETLOCAL enabledelayedexpansion

SET source="C:\source.srt"
SET target="C:\target.srt"

IF EXIST %target% DEL /f %target%

FOR /f "delims=" %%i IN ('FINDSTR . %source%') DO (
   SET line=%%i
   SET line=!line:ö=oe!
   SET line=!line:ä=ae!
   SET line=!line:ü=ue!
   ECHO !line! >> %target%
)
Eitan T
  • 32,660
  • 14
  • 72
  • 109
nixda
  • 2,654
  • 12
  • 49
  • 82
  • What are the >s for? And what is not working exactly? What are lines 12 and 13? Are they the ones with the ä and ü? – Eitan T Jul 31 '12 at 16:21
  • Sry, > was a format error by me :) Yes, line 12-13 are the lines with ä and ü. The first line with ö does work. What exactly doesnt work: ö is correctly replaced by oe, but ä and ü aren't replaced. – nixda Jul 31 '12 at 16:45
  • Well, it works for me. What do you get instead of the desired `ae`/`ue`? – Eitan T Jul 31 '12 at 16:50
  • Oh god, it worked and I missed it. After my first try, I searched for an ö in my target file and found some in upper cases. But what I doesn't know: The replace command is case sensitive. What a trap! And now I look like a fool :D – nixda Jul 31 '12 at 17:48
  • 1
    The replace command is actually case insensitive for letters [A-Z], [a-z]. However, it does not recognize the upper/lower case pairs for letters with diacriticals. So for your "case" with a diacritical it is case sensitive. – dbenham Jul 31 '12 at 18:33

1 Answers1

-2

Don't you want to use sed? There it would be a simple one line command.

sed -e 's/ö/oe/g' -e 's/ä/ae/g' -e 's/ü/ue/g' source.srt
martin
  • 2,520
  • 22
  • 29
  • Can the people that downvote this answer please elaborate on what's wrong with it? Thank you. – martin Dec 29 '19 at 23:02