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

前端 未结 4 577
情书的邮戳
情书的邮戳 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:07

    as there was no answer to the "why does my line starts with "RH"", I'll do some gravedigging.

    So, the  comes from the BOM (Byte Order Mark) which indicates the file is in UTF, and the way the bytes are written if necessary. for the answer: you can use

    if x%_var1:RH=%x NEQ x%_var1%x (echo %_var2%)
    

    this will check if RH is in %_var1% (if after replacing RH in the var, it is unchanged, RH is not in the var) which means, whether the Bom is here or not is not important. Though, you'll have problems if you want an exact match.

    another way to deal with it is to not include the bom in your file, which means saving either in ASCII or UTF-8 without BOM; Or using a tool to strip the bom from your UTF-8 file.

提交回复
热议问题