Solved

Script to find specific words in a text file and export them to another

Posted on 2011-09-19
4
346 Views
Last Modified: 2012-05-12
Hey guys,

I have exported all my computer names in a certain OU to a txt file using dsquery

Unforntunately it exports the computer names along with the CNs and all that good stuff
"CN=MTLWKSxxxx,OU=xxxx,OU=xxxxx,OU=xxxx,DC=xxxx,DC=com"

I need to find a way to extract the computername to another txt which they all start with mtlwksxxxx or mtllapxxxx where x is a set of 4 variable digits ,

So in the new txt file i just want the computer names to show

Thanks!
0
Comment
Question by:WBGames
4 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 36562549
Would extracting the information in the format you require by easier?

dsquery computer "ou=whatever,dc=domain,dc=com" -scope onelevel -name mtl* -o rdn > pclist.txt

-o rdn will extract just the relative dn.

Steve
0
 
LVL 7

Expert Comment

by:ednetman
ID: 36562560
What command are you running in dsquery?  I think there is an option to show only the hostname, as opposed to the full OU structure.
0
 
LVL 37

Expert Comment

by:Gerwin Jansen
ID: 36563106
When text.txt is your txt file containing:

"CN=MTLWKSxxxx,OU=xxxx,OU=xxxxx,OU=xxxx,DC=xxxx,DC=com"
"CN=MTLWKSxxxx,OU=xxxx,OU=xxxxx,OU=xxxx,DC=xxxx,DC=com"
"CN=MTLLAPxxxx,OU=xxxx,OU=xxxxx,OU=xxxx,DC=xxxx,DC=com"
"CN=MTLSRVxxxx,OU=xxxx,OU=xxxxx,OU=xxxx,DC=xxxx,DC=com"

This would extract your system names:

for /f "tokens=2 delims==," %f in (test.txt) do @echo %f | findstr "MTLWKS MTLLAP"

Open in new window


Output:

MTLWKSxxxx
MTLWKSxxxx
MTLLAPxxxx
0
 
LVL 1

Author Closing Comment

by:WBGames
ID: 36563113
thanks
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
batch file problem 5 45
Excel - Creating a Visual Basic Macro to change the active cell color 9 42
Change size 15 42
Music – name and composer 2 19
This story has been written with permission from the scammed victim, a valued client of mine – identity protected by request.
Digital marketing agencies have encountered both the opportunities and difficulties that emerge from working with a wide-ranging organizations.
Notifications on Experts Exchange help you keep track of your activity and updates in one place. Watch this video to learn how to use them on the site to quickly access the content that matters to you.
Articles on a wide range of technology and professional topics are available on Experts Exchange. These resources are written by members, for members, and can be written about any topic you feel passionate about. Learn how to best write an article t…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question