Reading from a csv file and extracting certain data columns based on first column value

前端 未结 4 574
情书的邮戳
情书的邮戳 2021-02-08 03:45

This is my first batch program and I have been searching online but still struggling to write up a solution.

I have the following CSV file:

\"RH\",2013/0         


        
4条回答
  •  不知归路
    2021-02-08 04:18

    You have a parsing issue. First end the for loop with ), after this you can use the new variables:

    @echo off
    :: Set input file in variable
    ::Set _InputFile=%1
    
    :: Store input line into different variables
    FOR /F "tokens=1-18* delims=," %%A IN (%_InputFile%) DO (
        Set "_var1=%%A"
        Set "_var2=%%B"
        Set "_var3=%%C"
        Set "_var4=%%D"
        Set "_var5=%%E"
        Set "_var6=%%F"
        Set "_var7=%%G"
        Set "_var8=%%H"
        Set "_var9=%%I"
        Set "_var10=%%J"
        Set "_var11=%%K"
        Set "_var12=%%L"
        Set "_var13=%%M"
        Set "_var14=%%N"
        Set "_var15=%%O"
        Set "_var16=%%P"
        Set "_var17=%%Q"
        Set "_var18=%%R"
    )
    
    IF "%_var1%"=="RH" echo %var2%
    

提交回复
热议问题