Substituir uma string por um caractere curinga em um arquivo de lote

0

Eu tenho esse arquivo em lotes e preciso pular o 'eco' de algumas linhas. Linhas que eu quero pular são:

W;;
A;;TE;Tr100;8;;31.79;SHIP-TE50;;
A;;TE;Tr100;8;;33.08;SHIP-TE50;;
and so on .

Eu quero usar apenas A;;TE;Tr100; e, em seguida, curinga para capturar a linha e ignorar a exibição dela. Ele funciona para W;; , mas não funciona para A;;TE; Como eu pude fazer isso?

@ECHO OFF    
cls

SETLOCAL ENABLEDELAYEDEXPANSION
SET /a number=%1-1
SET "sourcedir=z:\abc\def\ghi"
SET "filename1=%sourcedir%\jklm%number%.gwl"
SET "last="
FOR /f "delims=" %%a IN ('sort "%filename1%"') DO (
 IF "%%a"=="W;;" goto :break
 IF "%%a"=="A;;TE;*" goto :break 
 IF "%%a"=="!last!" ECHO %%a
 SET "last=%%a"
)
:break
GOTO :EOF
    
por susik 02.02.2017 / 03:07

1 resposta

1

Leia if /? ; você está usando o padrão de sintaxe IF [NOT] string1==string2 command :

string1==string2  Specifies a true condition if the specified text strings match.

Nada sobre curingas . No entanto, você pode aproveitar ao máximo o FINDSTR command :

FINDSTR will set %ERRORLEVEL% as follows:

  • 0 (False) a match is found in at least one line of at least one file.
  • 1 (True) if a match is not found in any line of any file, (or if the file is not found at all).
  • 2 Wrong syntax

An invalid switch will only print an error message in error stream.

Expressões regulares (Pesquisar padrões de texto)

FINDSTR pode usar os seguintes metacaracteres que possuem um significado especial como operador ou delimitador. O FINDSTR support para expressões regulares é limitado e não padrão , somente os seguintes metacaracteres são suportados:

 .         Wildcard: any character
 *         Repeat: zero or more occurances of previous character or class
 ^         Line position: beginning of line
 $         Line position: end of line
           … etc.

O snippet de código a seguir pode ajudar:

SET "last="
FOR /f "delims=" %%a IN ('sort "%filename1%"') DO (
  echo("%%a"|>NUL findstr "^\"A;;TE;.* ^\"W;;\"$"
  IF !errorlevel! EQU 0 (
      rem match:
      rem        either lines starting with A;;TE;
      rem            or lines equal to      W;;
      rem goto :break 
  ) else (
      IF "%%a"=="!last!" ECHO %%a
      SET "last=%%a"
  )
)
:break
    
por 02.02.2017 / 16:12

Tags