extracting specific lines of data from multiple text files, to convert to a single csv file

后端 未结 2 1198
梦毁少年i
梦毁少年i 2020-12-20 06:32

First, apologies for my poor coding ability, however I have spent a few hours reading the forums and giving it a crack, so I would really appreciate any help with the follow

相关标签:
2条回答
  • 2020-12-20 06:51
    @echo off
    setlocal EnableDelayedExpansion
    if exist result.csv del result.csv
    for %%f in (*.txt) do (
        set i=0
        for /F "delims=" %%l in (%%f) do (
            set /A i+=1
            set line!i!=%%l
        )
        echo %%f, !line3!, !line5!, !line7! >> result.csv
    )
    

    This Batch file process all .txt files in the directory, as you said.

    0 讨论(0)
  • 2020-12-20 06:51

    You could read the lines with another construct.

    setlocal EnableDelayedExpansion
    < %1 (
    Set /p line1=
    
    Set /p line2=
    Set /p line3=
    Set /p line4=
    Set /p line5=
    Set /p line6=
    Set /p line7=
    )
    Echo %1,!line3!,!line5!,!line7!
    

    Or with a loop (Andriy)

    Setlocal EnableDelayedExpansion
    <%1 (
      For /L %%n in (1 1 7) do (
        Set /p line%%n=
      )
    )
    Echo %1,!line3!,!line5!,!line7!
    
    0 讨论(0)
提交回复
热议问题