Search code examples
windowscmddos

Trim leading slashes using only a batch file


For where I work my hands are tied on what I can use in order to do what I want.

What I need to do is create a .bat that does a net view and outputs it to a .txt and remove the leading slashes from the output.

Getting the net view to a file is the easy part but removing the leading slashes is what I am having an issues with.

Not sure if it will matter but the naming system that my company uses is #####-XX-##

I have looked around quite a bit and have not been able to find a way to easily do this.

EDIT: Powershell is also something that could be used if someone has a script for that.


Solution

  • PowerShell:

    net view | select-string '^\\\\([^\\\s]+)' | foreach-object {
      $_.Matches[0].Groups[1].Value
    } | out-file netview.txt
    

    Bill