NET VIEW

J

JohnNews

Folks:

On my home network, I used the NET VIEW command (Net View /domain:MyDomain)
to generate the following output.

**********************************************************************
Server Name Remark

----------------------------------------------------------------------------
---
\\MACHINE1
\\MACHINE2
\\MACHINE3
\\MACHINE4
\\MACHINE5
The command completed successfully.
***********************************************************************


What is the syntax of the DOS commands that would allow me to clean up this
list in the following ways:

* First I want to remove the FIRST 3 lines and the LAST line of the
above NET VIEW output
* Next I would like to remove the first 2 characters (\\) of each
remaining line
* Finally I want to remove the computer named MACHINE5 and insert
MAINmachine instead


Thanks in advances,
John.
 
W

Walter Schulz

**********************************************************************
Server Name Remark

----------------------------------------------------------------------------
---
\\MACHINE1
\\MACHINE2
\\MACHINE3
\\MACHINE4
\\MACHINE5
The command completed successfully.
***********************************************************************


What is the syntax of the DOS commands that would allow me to clean up this
list in the following ways:

* First I want to remove the FIRST 3 lines and the LAST line of the
above NET VIEW output
* Next I would like to remove the first 2 characters (\\) of each
remaining line
* Finally I want to remove the computer named MACHINE5 and insert
MAINmachine instead

What is the purpose? Why not just mark the entries you like, copy them
and paste them into a txt file? Then you may search and replace the
strings you want.
Can't see the big deal here.

Ciao, Walter

PS: for /F "tokens=3 delims=\" %a in ('net view') do echo
%a>>output.txt
 
C

Clay Calvert

Folks:

On my home network, I used the NET VIEW command (Net View /domain:MyDomain)
to generate the following output.

**********************************************************************
Server Name Remark

----------------------------------------------------------------------------
---
\\MACHINE1
\\MACHINE2
\\MACHINE3
\\MACHINE4
\\MACHINE5
The command completed successfully.
***********************************************************************


What is the syntax of the DOS commands that would allow me to clean up this
list in the following ways:

* First I want to remove the FIRST 3 lines and the LAST line of the
above NET VIEW output
* Next I would like to remove the first 2 characters (\\) of each
remaining line
* Finally I want to remove the computer named MACHINE5 and insert
MAINmachine instead

for /f "delims=\ " %%a in ('net view ^| find "\\"') do (
if %%a NEQ MACHINE5 (echo %%a) else (echo MAINmachine))

For bonus points, can you set the above to write the output to a text
file in either scenario with only one redirection statement?

I know the regulars can do it. ; )

Clay Calvert
(e-mail address removed)
Replace "W" with "L"
 
J

JohnNews

CLAY:

Thanks, your code works on my system.

How should I modify the code to direct output data into a TEXT file
(COMPLIST.TXT).



Thanks,
John.
 
C

Clay Calvert

Clay it always amazes me what you guys do with batch commands...

That's a tremendous honor coming from you. C++, and Active Directory,
are both greek to me and you are such a master at both of them.

Thanks,

Clay Calvert
(e-mail address removed)
Replace "W" with "L"
 
C

Clay Calvert

CLAY:

Thanks, your code works on my system.

How should I modify the code to direct output data into a TEXT file
(COMPLIST.TXT).>

Thanks,
John.

Aw, now that's no fun. : ) I was hoping you'd give it a try, but I
guess not. I'll shorten the output file to CL.txt to minimize line
wrapping. The simplest way is this, but it requires two redirection
statements.

for /f "delims=\ " %%a in ('net view ^| find "\\"') do (
if %%a NEQ MACHINE5 (echo %%a>>CL.txt) else (echo
MAINmachine>>CL.txt))

Here's how to do it with one redirection stattement.

@echo off>CL.txt
for /f "delims=\ " %%a in ('net view ^| find "\\"') do (
(if %%a NEQ MACHINE5 (echo %%a) else (echo MAINmachine)>>CL.txt))

The above is only three lines.

Clay Calvert
(e-mail address removed)
Replace "W" with "L"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top