Search code examples
windowsbatch-filecmdlinefeed

Win Batch, separate single line to multiple


i have 2 different text files. Each contains a single line, containing several parameters and/or absolute paths. Each single parameter and/or path is enclosed in double quotes:

-d"some_param" -d"next_param"
-i"c:\some_path" -i"c:\other_path"

I want to split that into multiple lines, so one param or path is on a single line. I thought it might help to insert a specific separation token because one of the parameters or paths may contain a space. So i use LL_FF for an easier handling.

LL_FF

Content file 1:

-d"__CHAR_BIT=8"LL_FF -d"__SHRT_BIT=16"LL_FF -d"__INT_BIT=32"LL_FF -d"__LONG_BIT=32"LL_FF -d"CPU_S32K144HFT0VLLT"LL_FF  

Content file 2:

-i"C:\Users\somePath\s_proc\C_s32k_conf1\inc"LL_FF -i "C:\Users\somePath\s_sysprj\includes\prjIncludes\inc"LL_FF -i"C:\Users\somePath\s_sysprj\can\canDeviceDriver\inc"LL_FF -i"C:\Users\somePath\s_sysprj\hal\clock\inc"LL_FF -i"C:\Users\somePath\s_sysprj\hal\intWatchdog\inc"LL_FF -i"C:\Users\somePath\s_sysprj\hal\timer\inc"LL_FF -i"C:\Users\somePath\s_sysprj\hal\periphery\inc"LL_FF -i"C:\Users\somePath\s_sysprj\os\taskGroupManager\inc"LL_FF -i"C:\Users\somePath\s_sysprj\os\osInterface\inc"LL_FF

I failed to write a batch file generating the following output:

File 1:

-d"__CHAR_BIT=8"
-d"__SHRT_BIT=16"
-d"__INT_BIT=32"
-d"__LONG_BIT=32"
-d"CPU_S32K144HFT0VLLT"

File 2:

-i"C:\Users\somePath\s_proc\C_s32k_conf1\inc"
-i"C:\Users\somePath\s_sysprj\includes\prjIncludes\inc"
-i"C:\Users\somePath\s_sysprj\can\canDeviceDriver\inc"
-i"C:\Users\somePath\s_sysprj\hal\clock\inc"
-i"C:\Users\somePath\s_sysprj\hal\intWatchdog\inc"
-i"C:\Users\somePath\s_sysprj\hal\timer\inc"
-i"C:\Users\somePath\s_sysprj\hal\periphery\inc"
-i"C:\Users\somePath\s_sysprj\os\taskGroupManager\inc"
-i"C:\Users\somePath\s_sysprj\os\osInterface\inc"

In the param list there is a high possability it will contain special characters like spaces, *, = And it needs to be a batch script. Can somebody help me out please?

Thanks and kind regards.

What i tried: using replace syntax failed because of special chars \r\n

regarding this i tried this:

rem @echo off
SET /p _text=<defines.lnt
echo %_text%
echo
for %%f in ("%_text:LL_FF";"%") do echo aaa %%ff

i succeed in reading the file, but i receive no output from the loop.

I also found solutions that might work, but are far to complex to be of any use to me as i would need to much time to understand... So hence my post here.

Way to complex


Solution

  • The following is a batch file example of the code I provided in my comment:

    @Echo Off
    For /F "Delims=" %%A In ('Type File*.txt 2^>Nul') Do For %%B In (%%~A
    ) Do >>Params.txt Echo %%B
    

    This should put the line from each of the files, File1.txt and File2.txt, into a new file named Params.txt, each on a different line as requested.