Link to home
Start Free TrialLog in
Avatar of Program652
Program652Flag for United States of America

asked on

replacing four spaces in a text file

I have a text file (output of the dsquery command of several fields) that has a delimiter of four spaces.  I need to change the delimiter to something else (since data in some of the lines contain a single space) so I can import the file into a table.  I have a batch file (see code) that is close, but no cigar.  I cannot get the delims to see *multiple* spaces as a delimiter.  The behavior is to handle *any* number of spaces as one (1).
I have to deal ONLY in BATCH.  
No windows scripting,
No third party utilities.  
Ideas how to do this?
for /f "skip=2 tokens=1-5 delims= " %%i in (filename.txt) do @echo %%i~%%j~%%k~%%l

Open in new window

Avatar of AmazingTech
AmazingTech

hmm. Can you post an example of the filename.txt or the dsquery command if this attached code doesn't do what you want it to.

SETLOCAL ENABLEDELAYEDEXPANSION
for /f "skip=2 tokens=*" %%i in (filename.txt) do (
    Set Line=%%i
    for /l %%a in (1,1,10) do Set Line=!Line:  = !  
    @echo !Line: =~!
)

Open in new window

Avatar of Program652

ASKER

Find attached below a small sample (I changed names to protect the innocent) of the text file generated by the command:
dsquery * ou=accounts, dc=mydom,dc=net -limit 0 -attr mail cn givenname samaccountname sn showinaddressbook > test.txt

[As you can tell, I am querying for these fields from AD.]

Please note that
1) as far as I can tell, I cannot specify the delimiter of the dsquery command (else I would not have this problem!) and
2) our cn's have a space between the last and first name.  (this is also a problem with my original for loop.

test.txt
ASKER CERTIFIED SOLUTION
Avatar of AmazingTech
AmazingTech

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nice! Thanks :-)