Board logo

标题: [文本处理] 批处理设置变量中有特殊字符 报错| was unexpected at this time [打印本页]

作者: twl666666    时间: 2020-1-6 09:29     标题: 批处理设置变量中有特殊字符 报错| was unexpected at this time

求助各位大神,下面我写的bat  报错| was unexpected at this time(咋处理特殊字符|   ?)
现在我想判断a文件内容第一行是否和b文件内容第一行一直,是就输出log true,否是就输出log false
  1. @echo off
  2. SET localfile=E:\mce_lab\mce_lab_Source_File_In\a.csv
  3. SET validate=E:\mce_lab\mce_lab_Source_File_In\b.txt
  4. for /f %%i in ('powershell Get-Content %localfile% -TotalCount 1') do (SET lastfieldname=%%i)
  5.   
  6. for /f %%i in ('powershell Get-Content %validate% -TotalCount 1') do (SET va=%%i)
  7. if "%headfilename%" =="%SB%" (
  8.     echo true  >E:\mce_lab\mce_lab_etl\20202020log.txt
  9. )   else (
  10.     echo false >E:\mce_lab\mce_lab_etl\20202020log.txt
  11. )
复制代码
下面是a.csv内容
aa|bb|cc|dd|
b.txt内容
aa|bb|cc|dd|
作者: Batcher    时间: 2020-1-6 10:09

回复 1# twl666666
  1. @echo off
  2. set localfile="E:\mce_lab\mce_lab_Source_File_In\a.csv"
  3. set validate="E:\mce_lab\mce_lab_Source_File_In\b.txt"
  4. set /p lastfieldname=<%localfile%
  5. set /p va=<%validate%
  6. if "%lastfieldname%" equ "%va%" (
  7.     >"E:\mce_lab\mce_lab_etl\20202020log.txt" echo true
  8. ) else (
  9.     >"E:\mce_lab\mce_lab_etl\20202020log.txt" echo false
  10. )
复制代码

作者: twl666666    时间: 2020-1-6 10:52

回复 2# Batcher


  谢谢大佬~!




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2