You are not logged in.

#1 17 Oct 2008 10:01

killavirus
Member
Registered: 15 Oct 2008
Posts: 17

edit Text files

im looking for a way to remove all spaces and special charachters from a text file  any ideas ???

e.g.
from

Server Name            Remark

-------------------------------------------------------------------------------
\\JAYDELL1                                                                     
\\LIONEL                                                                       
\\OPTIMATERM                                                                   
\\ROB                  Optima Optiplex 1                                       
\\SBSERVER2003                                                                 
\\VAIO-LIONEL                                                                  
The command completed successfully.

to

JAYDELL1
LIONEL
OPTIMATERM
ROB
SBSERVER2003
VAIO-LIONEL

I can get as far as removing the odd line etc e.g. the first line but am having difficulty figuring out how to do the rest sad

Offline

#2 17 Oct 2008 13:13

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: edit Text files

I'm guessing you're doing a "net view" there ... you could use the "for /f" command to achieve the results you want.

In a script, something like this should do it:

for /f "usebackq tokens=1 skip=3 delims=\ " %%a in (`net view ^| find /v "The command completed successfully."`) do echo:%%~a

Last edited by bluesxman (17 Oct 2008 13:16)


cmd | *sh | ruby | chef

Offline

#3 17 Oct 2008 13:36

killavirus
Member
Registered: 15 Oct 2008
Posts: 17

Re: edit Text files

lol you make this look easy !!!

  What is the usebackq ?
i havnt seen that before ...

Offline

#4 17 Oct 2008 16:59

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: edit Text files

It changes the semantics of the "for" command, such that it uses back-quotes >`< rather than straight quotes >'< to wrap around a command, plus a couple of other bits.  I do a lot of "for" work from text files, so you generally need it to allow long file names, so use it by force of habit.


cmd | *sh | ruby | chef

Offline

#5 17 Oct 2008 18:21

killavirus
Member
Registered: 15 Oct 2008
Posts: 17

Re: edit Text files

thank you smile
A real good tidbit of information there smile

Offline

Board footer

Powered by