Hi,
I need a batch that use findstr or something like that that take a txt for input that have a line like:
Account name for installing services & interfaces - E_X\try
the script speared the domain and the user (speared by \)
and editing my line in script :
User =<username>(in this case try)
Domain=<domain>(in this case E_X)
Thanks in advance...
batch for grep in some other text for input
Moderator: DosItHelp
Re: batch for grep in some other text for input
Where you say 'speared' I think you mean 'separated'.
This works here. Input.txt has the data.
This works here. Input.txt has the data.
Code: Select all
@echo off
for /f "delims=" %%a in ('type "input.txt" ^| find "Account name for installing services"') do set "var=%%a"
set "var=%var:* - =%"
for /f "tokens=1,* delims=\" %%a in ("%var%") do set "user=%%b"&set "domain=%%a"
echo "user=%user%" "domain=%domain%"
pause
Re: batch for grep in some other text for input
Hi,thanks
Can you explain the line:
set "var=%var:* - =%"
?
Can you explain the line:
set "var=%var:* - =%"
?
Re: batch for grep in some other text for input
mor.bas wrote:Hi,thanks
Can you explain the line:
set "var=%var:* - =%"
?
Removes everything before the hyphen.
If you turned ECHO ON and watch the code execute you can see what it is doing. Seeing is believing.
Re: batch for grep in some other text for input
You may also try my FindRepl.bat program this way:
That is, you are looking for "Account name for installing services & interfaces - " text, followed by any string of alphanumeric characters and underscore (represented by \w) repeated one or more times (the +), a backslash (put it twice) and another similar value. The parentheses enclose the values you want to extract, that are displayed via /$:1:2 switch. Easy! Isn't it?
Antonio
Code: Select all
@echo off
for /F "tokens=1,2" %%a in ('^< test.txt FindRepl "Account name for installing services & interfaces - (\w+)\\(\w+)" /$:1:2') do (
set "domain=%%~a"
set "user=%%~b"
)
echo "domain=%domain%" "user=%user%"
pause
That is, you are looking for "Account name for installing services & interfaces - " text, followed by any string of alphanumeric characters and underscore (represented by \w) repeated one or more times (the +), a backslash (put it twice) and another similar value. The parentheses enclose the values you want to extract, that are displayed via /$:1:2 switch. Easy! Isn't it?
Antonio