How to Tody Up Piped files

G

Guest

Guest
Archived from groups: microsoft.public.windowsxp.general (More info?)

Anyone know how to tidy up piped files ? For example if on the command line
you type:

net user>c:\users.txt

The txt file will have a list of users setup on the PC but the way its
setout is in columns of 3. I want a single column for a lookup table say.
Anyone got any suggestions before I start trying to script something ?
 
Archived from groups: microsoft.public.windowsxp.general (More info?)

Jingle Man wrote:

> Anyone know how to tidy up piped files ? For example if on the command line
> you type:
>
> net user>c:\users.txt
>
> The txt file will have a list of users setup on the PC but the way its
> setout is in columns of 3. I want a single column for a lookup table say.
> Anyone got any suggestions before I start trying to script something ?
Hi,

Using a VBScript (.vbs file) is an option.

Put the script below in a file called LocalUsers.vbs, and run it in a
command prompt (cmd.exe), like this:

cscript.exe //Nologo "c:\some path\LocalUsers.vbs" >c:\users.txt


'--------------------8<----------------------
Set oWshNet = CreateObject("WScript.Network")
' get current computer name
sComputer = oWshNet.ComputerName

Set oComputer = GetObject("WinNT://" & sComputer & ",computer")
oComputer.Filter = Array("user")

For Each oUser In oComputer
WScript.Echo oUser.Name
Next
'--------------------8<----------------------


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
 
Archived from groups: microsoft.public.windowsxp.general (More info?)

"Jingle Man" <Jingle Man@discussions.microsoft.com> wrote in message
news:FEF2E18B-5B62-45F4-B016-9CA82325B43F@microsoft.com...
> Anyone know how to tidy up piped files ? For example if on the command
> line
> you type:
>
> net user>c:\users.txt
>
> The txt file will have a list of users setup on the PC but the way its
> setout is in columns of 3. I want a single column for a lookup table say.
> Anyone got any suggestions before I start trying to script something ?

[1]@echo off &setlocal enabledelayedexpansion
[2]for /f "skip=4 delims=" %%i in ('net users^|find /v "The command
completed" ') do (
[3] set ynu=%%i
[4] echo !ynu:~0,25!
[5] if not "!ynu:~25,25!"=="" echo !ynu:~25,25!
[6] if not "!ynu:~50,25!"=="" echo !ynu:~50,25!
[7] )

Each line begins [number]. Lines will be wrapped in transmission and
need to be rejoined. The [number] at the beginning of each line needs
to be removed.

Note that in line 2, FIND filters out the line "The command completed"
(which will be the last line generated by the "Net users" command.) I
suspect (but do not KNOW) that usernames cannot contain a dot. If the
usernames CANNOT contain dot, then use "." in place of "The command
completed" (since the "The command completed" line is terminated by a
dot....)

Pop a

>>filename

after each ECHO and you've got your list in your preferred form.

For batch methods, try alt.msdos.batch.nt or
microsoft.public.win2000.cmdprompt.admin

HTH

....Bill