# Replace a string with wildcard in a batch file

I have this batch file and I need skip 'echo' of some lines. Lines that I want to skip are:

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

I want to use only A;;TE;Tr100; and then wildcard to catch the line and skip displaying it. It works for W;; but it does not work for A;;TE; How could I do it?

@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
• I don't have your solution, but consider: find /i /v "A;;TE;*" "filetwo" >> outtwo – TOOGAM Feb 2 '17 at 4:51

Read if /?; you are using the IF [NOT] string1==string2 command syntax pattern:

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

Nothing about wildcards. However, you could make best of 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.

Regular Expressions (Search for patterns of text)

FINDSTR can use the following metacharacters which have special meaning either as an operator or delimiter. FINDSTR support for regular expressions is limited and non-standard, only the following metacharacters are supported:

.         Wildcard: any character
*         Repeat: zero or more occurances of previous character or class
^         Line position: beginning of line
$Line position: end of line … etc. Following code snippet could help: 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