CMD - 旋转/转置文件行 [例如转换 1500 行 (x1 col) --> 500 行 (x3 col)]

CMD - Pivot / Transpose lines of file [e.g. convert 1500 lines (x1 col) --> 500 lines (x3 col)]

请问我如何 'pivot' 或转置文件(即将单列列表转换为 table 数据)...

目前...

VideoA.name
VideoA.size
VideoA.bitrate
VideoB.name
VideoB.size
VideoB.bitrate
...

想要...

VideoA.name, VideoA.size, VideoA.bitrate
VideoB.name, VideoB.size, VideoB.bitrate
Name Size Bitrate
VideoA.name VideoA.size VideoA.bitrate
VideoB.name VideoB.size VideoB.bitrate

额外信息/上下文

我知道人们经常问 'why are you doing this?' 所以(如果有兴趣),这是我试图解决的更广泛的背景/问题...

GetProps_AllFiles.bat
---------------------

@ECHO OFF
SETLOCAL
FOR /F "tokens=*" %%A in (Files.txt) do (
    getprops %%A 0,1,320 /noheaders >> Details.csv
)

提前致谢!

使用“标准方式”(for /f)逐行读取文件,由计数器扩展。将行添加到字符串 (line),后跟一个逗号(或任何您想用作分隔符的内容),然后增加计数器。除了它是第三行。然后打印字符串加上当前行,重置计数器和字符串,然后重复。

@echo off
setlocal enabledelayedexpansion
set "line="
set count=0
(for /f "delims=" %%a in (test.txt) do (
  set /a count+=1
  if !count! equ 3 (
    echo !line!%%a
    set "line=" 
    set count=0
  ) else (
    set line=!line!%%a,
  )
))>test.csv

下面是对 友情提供的代码的轻微调整,允许将文件名和行数传递到脚本中...

ColumiseFile.cmd
----------------

@ECHO OFF
SETLOCAL enabledelayedexpansion

REM :: USAGE -----------------------------------------------------------------
REM ColumiseFile [1]File.txt [2]NumOfLines
REM > Concatenates every n Lines into 1, exporting result to File.csv
SET "File=%1"
SET /A Lines=%2

REM :: MAIN -------------------------------------------------------------------
REM Thanks to Stephan [
REM Loops through input file, compacting every n lines into 1
set "line="
set count=0
(for /f "delims=" %%a in (%File%) do (
  set /a count+=1
  if !count! equ %Lines% (
    echo !line!%%a
    set "line=" 
    set count=0
  ) else (
    set line=!line!%%a,
  )

REM :: OUTPUT -----------------------------------------------------------------
REM Create .csv in same location as source .txt file
))>%~dpn1.csv