mardi 7 août 2018

How to make the first part of the textlines unique and concatenate the second part in batch?

I have following lines in my formatliste_droid.txt:

Z:\15_Testdateien\jhove_Script_fuer_MIX-Verzeichnisse\testfiles\1002779294_sf_droid_no_match.pdf$fmt/95
Z:\15_Testdateien\jhove_Script_fuer_MIX-Verzeichnisse\testfiles\1002779294_sf_droid_no_match.pdf$fmt/477
Z:\15_Testdateien\jhove_Script_fuer_MIX-Verzeichnisse\testfiles\1002779294_sf_droid_no_match.pdf$fmt/354

The first part before $ is repeated and needs to be unique. The second part after $ is always different. So what I need is the transformation to one unique path concatenated with all second parts of the line after $

Z:\15_Testdateien\jhove_Script_fuer_MIX-Verzeichnisse\testfiles\1002779294_sf_droid_no_match.pdf$fmt/95$fmt/477$fmt/354

   @echo off
    setlocal EnableDelayedExpansion
    set "prevLine="
    for /F "tokens=1,2 delims=$" %%a in (formatliste_droid.txt) do (
       if "%%a" neq "!prevLine!" (
          echo %%a$%%b>>_formatliste_droid.txt
          set "prevLine=%%a"
       )

    )

With this code I can make unique line, but parts of the line after $ are lost except from the first line. Is there a way to concatenate them all with unique path?

Aucun commentaire:

Enregistrer un commentaire