Here's the code:
Code: Select all
@Echo Off
setlocal enabledelayedexpansion
Set target=my home ; sweet home
For /L "tokens=1 delims=; " %%a In (%target%) Do (
Echo %%a
)
endlocal
(Yes, I've looked at For /?)
Moderator: DosItHelp
Code: Select all
@Echo Off
setlocal enabledelayedexpansion
Set target=my home ; sweet home
For /L "tokens=1 delims=; " %%a In (%target%) Do (
Echo %%a
)
endlocal
Code: Select all
@Echo Off
setlocal enabledelayedexpansion
Set target=my home;sweet home
For /f "tokens=1,2* delims=;" %%a In ("%target%") Do (
Set tkns1= %%a
Set tkns2= %%b
)
Echo #1 tokens: %tkns1%
Echo #2 tokens: %tkns2%
endlocal
Code: Select all
@echo off
(
echo A them 1
echo A theme 1
echo A them 2
echo A anthem 1
)>file.txt
Findstr /irn /c:".* them .*" "file.txt"
pause
Code: Select all
@echo off
Findstr /irn /c:".* %~1 .*" "file.txt" |Findstr /ir /c:".* %~2 .*"
pause
Code: Select all
@Echo Off
Echo entered on command line: %1 AND %2
Echo.& Echo file contents:& Type file.txt
Echo.&Echo running Findstr...
Findstr /irn /c:".* %~1 .*" "file.txt" |Findstr /ir /c:".* %~2 .*"
Jer wrote:foxdrive, your first example picks up every 'them' but would ignore 'them,' . That's why
I've removed punctuation and converted all spaces to underscore plus the first
word has a leading _ and the last word ends with _.
Your second example does not display anything when I try it.
Code: Select all
d:\abc>A.BAT "them" "bill"
1:A them bill 1
3:A them and bill 2
d:\abc>type a.bat
@echo off
(
echo A them bill 1
echo A bill theme 1
echo A them and bill 2
echo A anthem 1
)>file.txt
Findstr /irn /c:".* %~1 .*" "file.txt" |Findstr /ir /c:".* %~2 .*"
For learning's sake could you see if I'm doing something wrong.
And finally, you taught me something: using parenthesis around a
block of echo-to-file commands.
Jer wrote:My command is: test1 them anthem
Code: Select all
@Echo Off
Echo entered on command line: %1 AND %2
Echo.& Echo file contents:& Type file.txt
Echo.&Echo running Findstr...
Findstr /irn /c:".* %~1 .*" /c:".* %~2 .*" "file.txt"
Code: Select all
@Echo Off
set "punc=[,.;:'?{}+=-_`~@#$&() ]"
Echo entered on command line: "%~1" AND "%~2"
Echo.& Echo file contents:& Type file.txt
Echo.&Echo running Findstr...
Findstr /irn /c:".*%punc%%~1%punc%.*" /c:".*%punc%%~2%punc%.*" "file.txt"
pause
Code: Select all
@Echo Off
set "punc=[,.;:'?{}+=-_`~@#$&() ]"
Echo entered on command line: "%~1" AND "%~2"
Echo.& Echo file contents:& Type file.txt
Echo.&Echo running Findstr...
If "%~2"=="" (
Findstr /irn /c:".*%punc%%~1%punc%.*" "file.txt"
) Else (
Findstr /irn /c:".*%punc%%~1%punc%.*" /c:".*%punc%%~2%punc%.*" "file.txt"
)
Code: Select all
If "%1"=="" Echo No args entered& Exit /b