Pulling certain charactors?

  • Thread starter Thread starter Ben Samuals
  • Start date Start date
B

Ben Samuals

I dump some text from a process this is formatted as follows:

cn=john smith,ou=myou,dc=mycompnay,dc=com
cn=suzy smith,ou=myou,dc=mycompnay,dc=com
cn=don smith,ou=myou,dc=mycompnay,dc=com....

What I want to do is pull the name from the above file. Could anyone help
with the "for" syntax? I would like to see:

john smith
suzy smith
don smith...

thank you.
 
@echo off & setlocal enableextensions enabledelayedexpansion
for /f "delims=," %%c in ('findstr cn= cn.txt') do (
set tempstr=%%c
set tempstr=!tempstr:~3!
echo !tempstr!
)
 
Or you can do this if you are sure every line in the file is an acceptable
line:
@echo off & setlocal enableextensions enabledelayedexpansion
for /f "delims=," %%c in (cn.txt) do (
set tempstr=%%c
set tempstr=!tempstr:~3!
echo !tempstr!
)
 
Paul, for some reaon when I enter this I get not output. This is what I am
running:

@echo off & setlocal enableextensions enabledelayedexpansion
for /f "delims=," %%a in ('findstr CN= test1.dat') do (set tempstr=%%a set
tempstr=~tempstr:~3! echo !tempstr!)

Did I must something?

thx, L
 
Paul R. Sadowski said:
Or you can do this if you are sure every line in the file is an acceptable
line:
@echo off & setlocal enableextensions enabledelayedexpansion
for /f "delims=," %%c in (cn.txt) do (
set tempstr=%%c
set tempstr=!tempstr:~3!
echo !tempstr!
)

Hello Paul,
what about a one liner:

for /f "tokens=2 delims=,=" %%A in (cn.txt) do @echo/%%A
 
Ben Samuals said:
Paul, for some reaon when I enter this I get not output. This is what I am
running:

@echo off & setlocal enableextensions enabledelayedexpansion
for /f "delims=," %%a in ('findstr CN= test1.dat') do (set tempstr=%%a set
tempstr=~tempstr:~3! echo !tempstr!)

Did I must something?

Yes, that were some more lines, you can't put them into one line without
putting an ampersand in between.
for /f "delims=," %%a in ('findstr CN= test1.dat') do (set tempstr=%%a &set >tempstr=~tempstr:~3! &echo !tempstr!)

Or use my one liner :
for /f "tokens=2 delims=,=" %%A in (cn.txt) do @echo/%%A
 
Ben Samuals said:
Paul, for some reaon when I enter this I get not output. This is what I am
running:

@echo off & setlocal enableextensions enabledelayedexpansion
for /f "delims=," %%a in ('findstr CN= test1.dat') do (set tempstr=%%a set
tempstr=~tempstr:~3! echo !tempstr!)

Did I must something?

In line 4 below you put a tilde where you should have put a bang. I
corrected it. (set tempstr=!tempstr:~3! NOT set tempstr=~tempstr:~3!)
@echo off & setlocal enableextensions enabledelayedexpansion
for /f "delims=," %%a in ('findstr CN= test1.dat') do (
set tempstr=%%a
set tempstr=!tempstr:~3!
echo !tempstr!
)
 
Ben Samuals said:
I dump some text from a process this is formatted as follows:

cn=john smith,ou=myou,dc=mycompnay,dc=com
cn=suzy smith,ou=myou,dc=mycompnay,dc=com
cn=don smith,ou=myou,dc=mycompnay,dc=com....

What I want to do is pull the name from the above file. Could anyone help
with the "for" syntax? I would like to see:

john smith
suzy smith
don smith...

Sorry, John, Suzy, and Don are not available to take your call. Do you need
these specific "characters" or will anyone do?

[sorry, I couldn't resist!]

But seriously, if you are extracting distinguished names to a file and then
parsing the output, you might find it more effective to deal directly with
the domain using ADSI scripting. That way you would be less susceptible to
unexpected syntactical errors that could result from non-standard common
names such as:

CN=Smith, John...
cn=suzy Q smith...

It all depends, of course, on the nature of what is producing the output for
you, and whether or not that functionality could be readily duplicated in a
script.


/Al
 
Back
Top