I don't think I managed to make myself clear..the log file would contain say " asgf agahi a hi af as L124334 Computer name" I require L124334
I am new to batch programming and would appreciate any help

Moderator: DosItHelp
Code: Select all
type file.log | repl ".* (.*?) computer .*" "$1" ai >newfile.txt
massij wrote:I could not really understand what the file does :S
massij wrote:for example how could I alter the file to show me the name if it follows and not preceeds the "Computer Name "
Code: Select all
type file.log | repl ".* computer (.*?) .*" "$1" ai >newfile.txt
massij wrote:OK thanks... and there is no way that I could somehow manage to write the code myself without using the other batch file ? since I would like to understand the code and be able to build on it
Code: Select all
@echo off
setlocal enableDelayedExpansion
for /F "tokens=* delims=" %%a in ('findstr /I "Computer name" "log.txt"') do (
set "line= %%a"
for /F "tokens=* delims=" %%b in (" Computer name!line:*Computer name=!") do set "praefix=!line:%%b=!"
for %%b in (!praefix!) do set "token=%%b"
echo(!token!
)
enbdlocal
goto :eof
In addition fixidrive's method should be faster.log.txt wrote:asdf
asgf agahi a hi af as L124334 Computer name
asgf agahi a hi af as !L124334! Computer name
asgf agahi a hi af as L124334! Computer name
asgf agahi a hi af as !L124334 Computer name
asgf agahi a hi af "as L124334" Computer name
asdf
asdf
Code: Select all
@echo off
setlocal disableDelayedExpansion
setlocal enableDelayedExpansion
for /F "tokens=* delims=" %%a in ('findstr /I "Computer name" "log.txt"') do (
endlocal
set "line= %%a"
setlocal enableDelayedExpansion
for /F "tokens=* delims=" %%b in (" Computer name!line:*Computer name=!") do (
endlocal
call set "praefix=%%line:%%b=%%"
setlocal enableDelayedExpansion
)
for %%b in (!praefix!) do (
endlocal
set "token=%%b"
setlocal enableDelayedExpansion
)
echo(!token!
)
endlocal
endlocal
goto :eof
penpen wrote:If you want to support ! characters this may help you:(Even more slow.)Code: Select all
<Snip>
</Snip>
penpen
Code: Select all
@Echo Off&SetLocal
Set "_="&Set "_T="
For /f "Tokens=*" %%A In ('Find /i "Computer Name"^<"file.log"') Do Call :SUB1 %%A$
Ping -n 6 127.0.0.1 1>Nul
GoTo :Eof
:SUB1
(Set _=%*)
(Set _T=Computer Name%_:*Computer Name=%)
Call :SUB2 %%_:%_T%=%%
Echo( %_T%
GoTo :Eof
:SUB2
For %%A In (%*) Do Set "_T=%%A"