BasicInfo

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

Re: BasicInfo

#16 Post by ghostmachine4 » 01 Jan 2011 00:24

ChickenSoup wrote:
ghostmachine4 wrote:there's no need to call ipconfig 2 times. Do something to the find ( or rather use findstr) to make it search for those 2 patterns at the same time.

ghostmachine4, I'm new to using findstr. Could you present an example of the better way to do it?

Code: Select all

ipconfig .... |  findstr /I "IP Address IPv4"

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: BasicInfo

#17 Post by aGerman » 01 Jan 2011 09:12

No. This is matching lines that contain IP or Address or IPv4.
IPv4 is useless then, it contains IP ....


Use the /c switch.

Code: Select all

ipconfig /all | findstr /i /c:"IP Address" /c:"IPv4 Address"


Regards
aGerman

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

Re: BasicInfo

#18 Post by ghostmachine4 » 02 Jan 2011 00:05

aGerman wrote:No. This is matching lines that contain IP or Address or IPv4.
IPv4 is useless then, it contains IP ....

I regret not using my favourite grep/gawk .

Code: Select all

ipconfig /all | grep -E "(IP|IPv4) Address"

mischi
Posts: 12
Joined: 24 Dec 2010 02:31

Re: BasicInfo

#19 Post by mischi » 13 Jan 2011 09:04

and last thing what I would like to know:

via net start I get list of running services, from it I want choose exact one (example: net start |findstr "DHCP Client") and here is problem if the command is able to find this service than he should do echo "Everything is OK".
Any idea how to do it? thanks.

ChickenSoup
Posts: 79
Joined: 13 Dec 2010 10:32

Re: BasicInfo

#20 Post by ChickenSoup » 13 Jan 2011 09:16

Code: Select all

net start | findstr /c:"DHCP Client">nul && echo.Everything is OK

mischi
Posts: 12
Joined: 24 Dec 2010 02:31

Re: BasicInfo

#21 Post by mischi » 13 Jan 2011 11:15

thank you ChickenSoup it's working as I wanted, would it be a problem to make a condition that if it doesn't work (service is not there), an error will appear(echo service is not running)? In this case I suppose IF Conditionaly perform command is necessary to use, or am I wrong? thanks.

ChickenSoup
Posts: 79
Joined: 13 Dec 2010 10:32

Re: BasicInfo

#22 Post by ChickenSoup » 14 Jan 2011 14:05

You could do an IF statement, but this is probably slicker:

Code: Select all

net start | findstr /c:"DHCP Client">nul && echo.Everything is OK || echo Service is not running

mischi
Posts: 12
Joined: 24 Dec 2010 02:31

Re: BasicInfo

#23 Post by mischi » 13 Mar 2011 10:47

guys, again additional question for you:
I want to check via this script remote computers so the question is how I can process it?
I guess one way is to use PsExec from sysinternals but maybe is it possible do it via command for?

Something like

Code: Select all

for /F %%G in (computers.txt) do script.bat

Does it make sense to you or is it stupid :oops:
thanks.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: BasicInfo

#24 Post by aGerman » 13 Mar 2011 11:17

Of course, it's possible. FOR /F reads your file line by line and saves the content of the current line to %%G.
But if you want to call another batch for each line then you have to let it know the value in %%G. This could be done via Argument.

Code: Select all

for /f %%G in (computers.txt) do call script.bat %%G

In script.bat you have to work with %1 for getting the value.

Regards
aGerman

mischi
Posts: 12
Joined: 24 Dec 2010 02:31

Re: BasicInfo

#25 Post by mischi » 06 Sep 2011 02:56

hi guys,
again after long time I need your help :)
now I would like to get one exact line from file on output

now I have something like it:

Code: Select all

for /f "tokens=*" %%a in ('type D:\test\test.txt') do (echo line=%%a)

but this command will show me all lines, I need only one exact line, I tried it combine with findstr command but without effect
Could you help me?
Many Thanks.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: BasicInfo

#26 Post by Ed Dyreen » 06 Sep 2011 07:05

'

Code: Select all

Which line ?
set /a skip = 0
set "$NotDefined="
for /f "usebackq skip=%skip% tokens=*" %%! in (
  "D:\test\test.txt"
) do if not defined $NotDefined (
  ::
  echo.line=%%!
  set /a $NotDefined = 1
)

pause
exit /b 0
Last edited by Ed Dyreen on 06 Sep 2011 08:22, edited 2 times in total.

mischi
Posts: 12
Joined: 24 Dec 2010 02:31

Re: BasicInfo

#27 Post by mischi » 06 Sep 2011 08:01

the line what I'm looking for always start with word "server" I checked/tested script above but it is not working.

Post Reply