@echo off
setlocal enabledelayedexpansion
set File=D:\Temp\test.txt
set Search=queued message from
for /f "tokens=1* delims=@" %%a in ('type "%File%" ^| find.exe /i "%Search%"') do (
REM *** Everything before the "@" is removed in %%b:
set From=%%b
REM *** Now that the leading spaces have been removed, remove everything after the email address:
for /f "tokens=1" %%f in ("!From!") do set From=%%f
REM *** Now add the ".*@" and escape the dots:
set From=.*\@!From:.=.\!
call :Process "!From!"
)
echo Done.
goto :eof
:Process
set From=%~1
echo Processing '%From%' ...
REM ...
goto :eof
@echo off
setlocal enabledelayedexpansion
set InFile=D:\Temp\test.txt
set OutFile=D:\Temp\testout.txt
set Search=queued message from
if exist "%OutFile%" del "%OutFile%"
echo Processing '%InFile%' ...
for /f "tokens=1* delims=@" %%a in ('type "%InFile%" ^| find.exe /i "%Search%"') do (
REM *** verything before the "@" is removed in %%b:
set From=%%b
REM *** Now that the leading spaces have been removed, remove everything after the email address:
for /f "tokens=1" %%f in ("!From!") do set From=%%f
REM *** Now add the ".*@" and escape the dots:
set From=from .*\@!From:.=.\!
>>"%OutFile%" echo !From!
)
echo Done.
@echo off
setlocal enabledelayedexpansion
set InFile=D:\Temp\test2.txt
set OutFile=D:\Temp\testout.txt
set Search=queued message from
set TempFile=%Temp%\%~n0.tmp
if exist "%OutFile%" del "%OutFile%"
if exist "%TempFile%" del "%TempFile%"
echo Processing '%InFile%' ...
for /f "tokens=1* delims=@" %%a in ('type "%InFile%" ^| find.exe /i "%Search%"') do (
REM *** Everything before the "@" is removed in %%b:
set From=%%b
REM *** Now that the leading spaces have been removed, remove everything after the email address:
for /f "tokens=1" %%f in ("!From!") do set From=%%f
REM *** Now add the "from .*@" and escape the dots:
set From=from .*\@!From:.=.\!
REM *** Write the output to a temp file
>>"%TempFile%" echo !From!
)
REM Remove duplicates from the list in the temp file, and create the output file
set Line=
for /f "delims=" %%a in ('type "%TempFile%" ^| sort.exe') do (
if /i not "!Line!"=="%%a" (
>>"%OutFile%" echo %%a
set Line=%%a
)
)
del "%TempFile%"
echo Done; results are in '%OutFile%'.
Open in new window